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 1da8c8ac9615..9a03fb8392b3 100644 --- a/lib/node_modules/@stdlib/math/base/napi/unary/README.md +++ b/lib/node_modules/@stdlib/math/base/napi/unary/README.md @@ -301,6 +301,66 @@ The function accepts the following arguments: void stdlib_math_base_napi_d_d( napi_env env, napi_callback_info info, double (*fcn)( double ) ); ``` +#### STDLIB_MATH_BASE_NAPI_MODULE_D_F( fcn ) + +Macro for registering a Node-API module exporting an interface for invoking a unary function accepting a double-precision floating-point number and returning a single-precision floating-point number. + +```c +static float fcn( const double x ) { + return (float)x; +} + +// ... + +// Register a Node-API module: +STDLIB_MATH_BASE_NAPI_MODULE_D_F( fcn ); +``` + +The macro expects the following arguments: + +- **fcn**: `float (*fcn)( double )` 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_d_f( env, info, fcn ) + +Invokes a unary function accepting a double-precision floating-point number and returning a single-precision floating-point number. + +```c +#include + +// ... + +static float fcn( const double x ) { + return (float)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_d_f( 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] float (*fcn)( double )` unary function. + +```c +void stdlib_math_base_napi_d_f( napi_env env, napi_callback_info info, float (*fcn)( double ) ); +``` + #### STDLIB_MATH_BASE_NAPI_MODULE_F_F( fcn ) Macro for registering a Node-API module exporting an interface for invoking a unary function accepting and returning single-precision floating-point numbers. 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 4e8d5735fc0b..ee13e1963d13 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 @@ -23,6 +23,7 @@ #include "stdlib/math/base/napi/unary/c_c.h" #include "stdlib/math/base/napi/unary/c_f.h" #include "stdlib/math/base/napi/unary/d_d.h" +#include "stdlib/math/base/napi/unary/d_f.h" #include "stdlib/math/base/napi/unary/f_f.h" #include "stdlib/math/base/napi/unary/f_i.h" #include "stdlib/math/base/napi/unary/i_d.h" diff --git a/lib/node_modules/@stdlib/math/base/napi/unary/include/stdlib/math/base/napi/unary/d_f.h b/lib/node_modules/@stdlib/math/base/napi/unary/include/stdlib/math/base/napi/unary/d_f.h new file mode 100644 index 000000000000..eb079e0a0c41 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/napi/unary/include/stdlib/math/base/napi/unary/d_f.h @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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_D_F_H +#define STDLIB_MATH_BASE_NAPI_UNARY_D_F_H + +#include +#include + +/** +* Macro for registering a Node-API module exporting an interface invoking a unary function accepting a double-precision floating-point number and returning a single-precision floating-point number. +* +* @param fcn unary function +* +* @example +* static float fcn( const double x ) { +* return (float)x; +* } +* +* // ... +* +* // Register a Node-API module: +* STDLIB_MATH_BASE_NAPI_MODULE_D_F( fcn ); +*/ +#define STDLIB_MATH_BASE_NAPI_MODULE_D_F( fcn ) \ + static napi_value stdlib_math_base_napi_d_f_wrapper( \ + napi_env env, \ + napi_callback_info info \ + ) { \ + return stdlib_math_base_napi_d_f( env, info, fcn ); \ + }; \ + static napi_value stdlib_math_base_napi_d_f_init( \ + napi_env env, \ + napi_value exports \ + ) { \ + napi_value fcn; \ + napi_status status = napi_create_function( \ + env, \ + "exports", \ + NAPI_AUTO_LENGTH, \ + stdlib_math_base_napi_d_f_wrapper, \ + NULL, \ + &fcn \ + ); \ + assert( status == napi_ok ); \ + return fcn; \ + }; \ + NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_d_f_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 double-precision floating-point number and returning a single-precision floating-point number. +*/ +napi_value stdlib_math_base_napi_d_f( napi_env env, napi_callback_info info, float (*fcn)( double ) ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_NAPI_UNARY_D_F_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 a8963755942a..5b4f3470f85a 100644 --- a/lib/node_modules/@stdlib/math/base/napi/unary/manifest.json +++ b/lib/node_modules/@stdlib/math/base/napi/unary/manifest.json @@ -28,6 +28,7 @@ "./src/c_c.c", "./src/c_f.c", "./src/d_d.c", + "./src/d_f.c", "./src/f_f.c", "./src/f_i.c", "./src/i_d.c", diff --git a/lib/node_modules/@stdlib/math/base/napi/unary/src/d_f.c b/lib/node_modules/@stdlib/math/base/napi/unary/src/d_f.c new file mode 100644 index 000000000000..28a1a83926f9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/napi/unary/src/d_f.c @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/d_f.h" +#include +#include + +/** +* Invokes a unary function accepting a double-precision floating-point number and returning a single-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_d_f( napi_env env, napi_callback_info info, float (*fcn)( double ) ) { + 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; + } + + double x; + status = napi_get_value_double( 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; +}