From 4e25739c06a0407e20bc00f707a0564d66b159dc Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Tue, 9 Jul 2024 15:30:56 +0530 Subject: [PATCH 1/9] feat: add a function for dii_d in math/base/napi/ternary --- .../@stdlib/math/base/napi/ternary/README.md | 60 +++++++++++++++ .../include/stdlib/math/base/napi/ternary.h | 47 ++++++++++++ .../@stdlib/math/base/napi/ternary/src/main.c | 76 +++++++++++++++++++ 3 files changed, 183 insertions(+) diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md index f2f386aa9e13..a37a72ab16fb 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md @@ -182,6 +182,45 @@ The function accepts the following arguments: void stdlib_math_base_napi_fff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float, float ) ); ``` +#### stdlib_math_base_napi_dii_d( env, info, fcn ) + +Invokes a ternary function accepting a double precision floating point number and two signed 32-bit integers and returning a double-precision floating-point number. + +```c +#include + +// ... + +static double add( const double x, const int32_t y, const int32_t z ) { + return x + y + z; +} + +// ... + +/** +* 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_dii_d( env, info, add ); +} + +// ... +``` + +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] double (*fcn)( double, int32_t, int32_t )` ternary function. + +```c +void stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) ); +``` + #### STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( fcn ) Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting and returning double-precision floating-point numbers. @@ -224,6 +263,27 @@ The macro expects the following arguments: 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_MODULE_DII_D( fcn ) + +Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting a double precision floating point number and two signed 32-bit integers and returning a double-precision floating-point number. + +```c +static double add( const double x, const int32_t y, const int32_t z ) { + return x + y + z; +} + +// ... + +// Register a Node-API module: +STDLIB_MATH_BASE_NAPI_MODULE_DII_D( add ); +``` + +The macro expects the following arguments: + +- **fcn**: `double (*fcn)( double, int32_t, int32_t )` ternary function. + +When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration. + diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h index 78ea9d67419a..ebbecb1c1349 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h @@ -102,6 +102,48 @@ }; \ NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_fff_f_init ) +/** +* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting a double precision floating point number and two signed 32-bit integers and returning a double-precision floating-point number. +* +* @param fcn ternary function +* +* @example +* #include +* +* static double add( const double x, const int_32 y, const int_32 z ) { +* return x + y + z; +* } +* +* // ... +* +* // Register a Node-API module: +* STDLIB_MATH_BASE_NAPI_MODULE_DII_D( add ); +*/ +#define STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn ) \ + static napi_value stdlib_math_base_napi_dii_d_wrapper( \ + napi_env env, \ + napi_callback_info info \ + ) { \ + return stdlib_math_base_napi_dii_d( env, info, fcn ); \ + }; \ + static napi_value stdlib_math_base_napi_dii_d_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_dii_d_wrapper, \ + NULL, \ + &fcn \ + ); \ + assert( status == napi_ok ); \ + return fcn; \ + }; \ + NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_dii_d_init ) + /* * If C++, prevent name mangling so that the compiler emits a ternary file having undecorated names, thus mirroring the behavior of a C compiler. */ @@ -119,6 +161,11 @@ napi_value stdlib_math_base_napi_ddd_d( napi_env env, napi_callback_info info, d */ napi_value stdlib_math_base_napi_fff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float, float ) ); +/** +* Invokes a ternary function accepting a double precision floating point number and two signed 32-bit integers and returning a double-precision floating-point number. +*/ +napi_value stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) ); + #ifdef __cplusplus } #endif diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c b/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c index 60efcb7c46e8..44ed32170df1 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c @@ -172,3 +172,79 @@ napi_value stdlib_math_base_napi_fff_f( napi_env env, napi_callback_info info, f return v; } + +/** +* Invokes a ternary function accepting a double precision floating point number and two signed 32-bit integers and returning a double-precision floating-point number. +* +* ## Notes +* +* - This function expects that the callback `info` argument provides access to the following JavaScript arguments: +* +* - `x`: input value. +* - `y`: input value. +* - `z`: input value. +* +* @param env environment under which the function is invoked +* @param info callback data +* @param fcn ternary function +* @return function return value as a Node-API double-precision floating-point number +*/ +napi_value stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) ) { + napi_status status; + + size_t argc = 3; + napi_value argv[ 3 ]; + status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); + assert( status == napi_ok ); + + if ( argc < 3 ) { + status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." ); + 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. First argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype2; + status = napi_typeof( env, argv[ 2 ], &vtype2 ); + assert( status == napi_ok ); + if ( vtype2 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + double x; + status = napi_get_value_double( env, argv[ 0 ], &x ); + assert( status == napi_ok ); + + int32_t y; + status = napi_get_value_int32_t( env, argv[ 1 ], &y ); + assert( status == napi_ok ); + + int32_t z; + status = napi_get_value_int32_t( env, argv[ 2 ], &z ); + assert( status == napi_ok ); + + napi_value v; + status = napi_create_double( env, fcn( x, y, z ), &v ); + assert( status == napi_ok ); + + return v; +} From f86a284f90f5fd21ba7765f47a4b058043b49e96 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 9 Jul 2024 03:27:06 -0700 Subject: [PATCH 2/9] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/math/base/napi/ternary/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md index a37a72ab16fb..477d04d20997 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md @@ -184,7 +184,7 @@ void stdlib_math_base_napi_fff_f( napi_env env, napi_callback_info info, float ( #### stdlib_math_base_napi_dii_d( env, info, fcn ) -Invokes a ternary function accepting a double precision floating point number and two signed 32-bit integers and returning a double-precision floating-point number. +Invokes a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number. ```c #include From d978c43c7efa7fb057474f3ceeaa85a91087785a Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 9 Jul 2024 03:29:02 -0700 Subject: [PATCH 3/9] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/math/base/napi/ternary/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md index 477d04d20997..0eff931c6a1e 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md @@ -191,8 +191,8 @@ Invokes a ternary function accepting a double-precision floating-point number an // ... -static double add( const double x, const int32_t y, const int32_t z ) { - return x + y + z; +static double fcn( const double x, const int32_t y, const int32_t z ) { + // ... } // ... @@ -205,7 +205,7 @@ static double add( const double x, const int32_t y, const int32_t z ) { * @return Node-API value */ napi_value addon( napi_env env, napi_callback_info info ) { - return stdlib_math_base_napi_dii_d( env, info, add ); + return stdlib_math_base_napi_dii_d( env, info, fcn ); } // ... From 7fb3040f3d361035cffcdda84687fc33ad51ec6c Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 9 Jul 2024 03:29:49 -0700 Subject: [PATCH 4/9] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/math/base/napi/ternary/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md index 0eff931c6a1e..cb3add290d80 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md @@ -268,14 +268,14 @@ When used, this macro should be used **instead of** `NAPI_MODULE`. The macro inc Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting a double precision floating point number and two signed 32-bit integers and returning a double-precision floating-point number. ```c -static double add( const double x, const int32_t y, const int32_t z ) { - return x + y + z; +static double fcn( const double x, const int32_t y, const int32_t z ) { + // ... } // ... // Register a Node-API module: -STDLIB_MATH_BASE_NAPI_MODULE_DII_D( add ); +STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn ); ``` The macro expects the following arguments: From 782c4882aa516af1364ca12a95546e6885dcdc1a Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 9 Jul 2024 03:30:16 -0700 Subject: [PATCH 5/9] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/math/base/napi/ternary/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md index cb3add290d80..a5c811768454 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md @@ -265,7 +265,7 @@ When used, this macro should be used **instead of** `NAPI_MODULE`. The macro inc #### STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn ) -Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting a double precision floating point number and two signed 32-bit integers and returning a double-precision floating-point number. +Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number. ```c static double fcn( const double x, const int32_t y, const int32_t z ) { From d5d6c87c792ff3ce08b6fab84ec854d6daad61e8 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 9 Jul 2024 03:30:57 -0700 Subject: [PATCH 6/9] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/math/base/napi/ternary/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md index a5c811768454..4dca5fb065f2 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md @@ -188,6 +188,7 @@ Invokes a ternary function accepting a double-precision floating-point number an ```c #include +#include // ... @@ -268,6 +269,8 @@ When used, this macro should be used **instead of** `NAPI_MODULE`. The macro inc Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number. ```c +#include + static double fcn( const double x, const int32_t y, const int32_t z ) { // ... } From c2a0d774aa6a4b17689399a96799ed2ee64c4c56 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 9 Jul 2024 03:33:01 -0700 Subject: [PATCH 7/9] Apply suggestions from code review Signed-off-by: Athan --- .../ternary/include/stdlib/math/base/napi/ternary.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h index ebbecb1c1349..514b72add029 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h @@ -103,21 +103,21 @@ NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_fff_f_init ) /** -* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting a double precision floating point number and two signed 32-bit integers and returning a double-precision floating-point number. +* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number. * * @param fcn ternary function * * @example * #include * -* static double add( const double x, const int_32 y, const int_32 z ) { -* return x + y + z; +* static double fcn( const double x, const int_32 y, const int_32 z ) { +* // ... * } * * // ... * * // Register a Node-API module: -* STDLIB_MATH_BASE_NAPI_MODULE_DII_D( add ); +* STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn ); */ #define STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn ) \ static napi_value stdlib_math_base_napi_dii_d_wrapper( \ @@ -162,7 +162,7 @@ napi_value stdlib_math_base_napi_ddd_d( napi_env env, napi_callback_info info, d napi_value stdlib_math_base_napi_fff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float, float ) ); /** -* Invokes a ternary function accepting a double precision floating point number and two signed 32-bit integers and returning a double-precision floating-point number. +* Invokes a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number. */ napi_value stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) ); From aed834b48447c2cec21bbea03097c6809dcac57f Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 9 Jul 2024 03:33:48 -0700 Subject: [PATCH 8/9] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c b/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c index 44ed32170df1..f8c7f232a366 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c @@ -174,7 +174,7 @@ napi_value stdlib_math_base_napi_fff_f( napi_env env, napi_callback_info info, f } /** -* Invokes a ternary function accepting a double precision floating point number and two signed 32-bit integers and returning a double-precision floating-point number. +* Invokes a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number. * * ## Notes * From cdf571241ddc1c4c71ef31beab3afea03438bdd8 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 9 Jul 2024 03:35:09 -0700 Subject: [PATCH 9/9] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c b/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c index f8c7f232a366..92b89ca0999e 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c @@ -235,11 +235,11 @@ napi_value stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, d assert( status == napi_ok ); int32_t y; - status = napi_get_value_int32_t( env, argv[ 1 ], &y ); + status = napi_get_value_int32( env, argv[ 1 ], &y ); assert( status == napi_ok ); int32_t z; - status = napi_get_value_int32_t( env, argv[ 2 ], &z ); + status = napi_get_value_int32( env, argv[ 2 ], &z ); assert( status == napi_ok ); napi_value v;