From defcea262e756a6c2eecce39fb0a35064f44619a Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 13 Jan 2026 18:20:45 +0530 Subject: [PATCH 1/3] feat: add initial macro setup --- .../@stdlib/math/base/napi/unary/README.md | 65 ++++++++++++++ .../include/stdlib/math/base/napi/unary.h | 1 + .../include/stdlib/math/base/napi/unary/i_h.h | 86 +++++++++++++++++++ .../math/base/napi/unary/manifest.json | 1 + .../@stdlib/math/base/napi/unary/src/i_h.c | 72 ++++++++++++++++ 5 files changed, 225 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/napi/unary/include/stdlib/math/base/napi/unary/i_h.h create mode 100644 lib/node_modules/@stdlib/math/base/napi/unary/src/i_h.c diff --git a/lib/node_modules/@stdlib/math/base/napi/unary/README.md b/lib/node_modules/@stdlib/math/base/napi/unary/README.md index cd85e52365e7..d5ffd5cac77b 100644 --- a/lib/node_modules/@stdlib/math/base/napi/unary/README.md +++ b/lib/node_modules/@stdlib/math/base/napi/unary/README.md @@ -736,6 +736,71 @@ The function accepts the following arguments: void stdlib_math_base_napi_i_f( napi_env env, napi_callback_info info, float (*fcn)( int32_t ) ); ``` +#### STDLIB_MATH_BASE_NAPI_MODULE_I_H( fcn ) + +Macro for registering a Node-API module exporting an interface for invoking a unary function accepting a signed 32-bit integer and returning a half-precision floating-point number. + +```c +#include "stdlib/number/float16/ctor.h" +#include + +static stdlib_float16_t fcn( const int32_t x ) { + // ... +} + +// ... + +// Register a Node-API module: +STDLIB_MATH_BASE_NAPI_MODULE_I_H( fcn ); +``` + +The macro expects the following arguments: + +- **fcn**: `stdlib_float16_t (*fcn)( int32_t )` unary function. + +When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration. + +#### stdlib_math_base_napi_i_h( env, info, fcn ) + +Invokes a unary function accepting a signed 32-bit integer and returning a half-precision floating-point number. + +```c +#include "stdlib/number/float16/ctor.h" +#include +#include + +// ... + +static stdlib_float16_t fcn( const int32_t x ) { + // ... +} + +// ... + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +napi_value addon( napi_env env, napi_callback_info info ) { + return stdlib_math_base_napi_i_h( env, info, fcn ); +} + +// ... +``` + +The function accepts the following arguments: + +- **env**: `[in] napi_env` environment under which the function is invoked. +- **info**: `[in] napi_callback_info` callback data. +- **fcn**: `[in] stdlib_float16_t (*fcn)( int32_t )` unary function. + +```c +void stdlib_math_base_napi_i_h( napi_env env, napi_callback_info info, stdlib_float16_t (*fcn)( int32_t ) ); +``` + #### STDLIB_MATH_BASE_NAPI_MODULE_I_I( fcn ) Macro for registering a Node-API module exporting an interface for invoking a unary function accepting and returning 32-bit signed integers. diff --git a/lib/node_modules/@stdlib/math/base/napi/unary/include/stdlib/math/base/napi/unary.h b/lib/node_modules/@stdlib/math/base/napi/unary/include/stdlib/math/base/napi/unary.h index 752f0a2c803a..70ab6990d71c 100644 --- a/lib/node_modules/@stdlib/math/base/napi/unary/include/stdlib/math/base/napi/unary.h +++ b/lib/node_modules/@stdlib/math/base/napi/unary/include/stdlib/math/base/napi/unary.h @@ -30,6 +30,7 @@ #include "stdlib/math/base/napi/unary/h_h.h" #include "stdlib/math/base/napi/unary/i_d.h" #include "stdlib/math/base/napi/unary/i_f.h" +#include "stdlib/math/base/napi/unary/i_h.h" #include "stdlib/math/base/napi/unary/i_i.h" #include "stdlib/math/base/napi/unary/k_k.h" #include "stdlib/math/base/napi/unary/s_s.h" diff --git a/lib/node_modules/@stdlib/math/base/napi/unary/include/stdlib/math/base/napi/unary/i_h.h b/lib/node_modules/@stdlib/math/base/napi/unary/include/stdlib/math/base/napi/unary/i_h.h new file mode 100644 index 000000000000..f66903456097 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/napi/unary/include/stdlib/math/base/napi/unary/i_h.h @@ -0,0 +1,86 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef STDLIB_MATH_BASE_NAPI_UNARY_I_H_H +#define STDLIB_MATH_BASE_NAPI_UNARY_I_H_H + +#include "stdlib/number/float16/ctor.h" +#include +#include +#include + +/** +* Macro for registering a Node-API module exporting an interface invoking a unary function accepting a signed 32-bit integer and returning a half-precision floating-point number. +* +* @param fcn unary function +* +* @example +* #include "stdlib/number/float16/ctor.h" +* #include +* +* static stdlib_float16_t fcn( const int32_t x ) { +* // ... +* } +* +* // ... +* +* // Register a Node-API module: +* STDLIB_MATH_BASE_NAPI_MODULE_I_H( fcn ); +*/ +#define STDLIB_MATH_BASE_NAPI_MODULE_I_H( fcn ) \ + static napi_value stdlib_math_base_napi_i_h_wrapper( \ + napi_env env, \ + napi_callback_info info \ + ) { \ + return stdlib_math_base_napi_i_h( env, info, fcn ); \ + }; \ + static napi_value stdlib_math_base_napi_i_h_init( \ + napi_env env, \ + napi_value exports \ + ) { \ + napi_value f; \ + napi_status status = napi_create_function( \ + env, \ + "exports", \ + NAPI_AUTO_LENGTH, \ + stdlib_math_base_napi_i_h_wrapper, \ + NULL, \ + &f \ + ); \ + assert( status == napi_ok ); \ + return f; \ + }; \ + NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_i_h_init ) + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Invokes a unary function accepting a signed 32-bit integer and returning a half-precision floating-point number. +*/ +napi_value stdlib_math_base_napi_i_h( napi_env env, napi_callback_info info, stdlib_float16_t (*fcn)( int32_t ) ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_NAPI_UNARY_I_H_H diff --git a/lib/node_modules/@stdlib/math/base/napi/unary/manifest.json b/lib/node_modules/@stdlib/math/base/napi/unary/manifest.json index 30a32d400a23..bcc2fab6917c 100644 --- a/lib/node_modules/@stdlib/math/base/napi/unary/manifest.json +++ b/lib/node_modules/@stdlib/math/base/napi/unary/manifest.json @@ -35,6 +35,7 @@ "./src/h_h.c", "./src/i_d.c", "./src/i_f.c", + "./src/i_h.c", "./src/i_i.c", "./src/k_k.c", "./src/s_s.c", diff --git a/lib/node_modules/@stdlib/math/base/napi/unary/src/i_h.c b/lib/node_modules/@stdlib/math/base/napi/unary/src/i_h.c new file mode 100644 index 000000000000..8b2cbf36ceaf --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/napi/unary/src/i_h.c @@ -0,0 +1,72 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/math/base/napi/unary/i_h.h" +#include "stdlib/number/float16/base/to_float64.h" +#include "stdlib/number/float16/ctor.h" +#include +#include +#include + +/** +* Invokes a unary function accepting a signed 32-bit integer and returning a half-precision floating-point number. +* +* ## Notes +* +* - This function expects that the callback `info` argument provides access to the following JavaScript arguments: +* +* - `x`: input value. +* +* @param env environment under which the function is invoked +* @param info callback data +* @param fcn unary function +* @return function return value as a Node-API double-precision floating-point number +*/ +napi_value stdlib_math_base_napi_i_h( napi_env env, napi_callback_info info, float (*fcn)( int32_t ) ) { + napi_status status; + + size_t argc = 1; + napi_value argv[ 1 ]; + status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); + assert( status == napi_ok ); + + if ( argc < 1 ) { + status = napi_throw_error( env, NULL, "invalid invocation. Must provide a number." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. Must provide a number." ); + assert( status == napi_ok ); + return NULL; + } + + int32_t x; + status = napi_get_value_int32( env, argv[ 0 ], &x ); + assert( status == napi_ok ); + + napi_value v; + status = napi_create_double( env, (double)fcn( x ), &v ); + assert( status == napi_ok ); + + return v; +} From ab5fa540c52bd1a5f4a97a58f5c16cfaa6fce5f9 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 13 Jan 2026 18:23:49 +0530 Subject: [PATCH 2/3] chore: update C header files --- lib/node_modules/@stdlib/math/base/napi/unary/src/i_h.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/napi/unary/src/i_h.c b/lib/node_modules/@stdlib/math/base/napi/unary/src/i_h.c index 8b2cbf36ceaf..1eab7a461a5f 100644 --- a/lib/node_modules/@stdlib/math/base/napi/unary/src/i_h.c +++ b/lib/node_modules/@stdlib/math/base/napi/unary/src/i_h.c @@ -17,7 +17,6 @@ */ #include "stdlib/math/base/napi/unary/i_h.h" -#include "stdlib/number/float16/base/to_float64.h" #include "stdlib/number/float16/ctor.h" #include #include From def394e695adcf6ba073f0cd24c5cb76b83e3096 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 13 Jan 2026 18:27:12 +0530 Subject: [PATCH 3/3] chore: clean up --- lib/node_modules/@stdlib/math/base/napi/unary/src/i_h.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/napi/unary/src/i_h.c b/lib/node_modules/@stdlib/math/base/napi/unary/src/i_h.c index 1eab7a461a5f..9843d3c0fbb8 100644 --- a/lib/node_modules/@stdlib/math/base/napi/unary/src/i_h.c +++ b/lib/node_modules/@stdlib/math/base/napi/unary/src/i_h.c @@ -36,7 +36,7 @@ * @param fcn unary function * @return function return value as a Node-API double-precision floating-point number */ -napi_value stdlib_math_base_napi_i_h( napi_env env, napi_callback_info info, float (*fcn)( int32_t ) ) { +napi_value stdlib_math_base_napi_i_h( napi_env env, napi_callback_info info, stdlib_float16_t (*fcn)( int32_t ) ) { napi_status status; size_t argc = 1;