diff --git a/lib/node_modules/@stdlib/math/base/special/wrap/manifest.json b/lib/node_modules/@stdlib/math/base/special/wrap/manifest.json index d89e21f11198..b2f19cbfa4f3 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrap/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/wrap/manifest.json @@ -1,5 +1,7 @@ { - "options": {}, + "options": { + "task": "build" + }, "fields": [ { "field": "src", @@ -24,6 +26,7 @@ ], "confs": [ { + "task": "build", "src": [ "./src/main.c" ], @@ -33,8 +36,45 @@ "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/math/base/napi/ternary", "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/trunc" + "@stdlib/math/base/special/trunc", + "@stdlib/math/base/special/fmod", + "@stdlib/math/base/assert/is-negative-zero" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/trunc", + "@stdlib/math/base/special/fmod", + "@stdlib/math/base/assert/is-negative-zero" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/trunc", + "@stdlib/math/base/special/fmod", + "@stdlib/math/base/assert/is-negative-zero" ] } ] diff --git a/lib/node_modules/@stdlib/math/base/special/wrap/src/addon.c b/lib/node_modules/@stdlib/math/base/special/wrap/src/addon.c index da1c76652da1..a2404d55ee2c 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrap/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/wrap/src/addon.c @@ -17,97 +17,7 @@ */ #include "stdlib/math/base/special/wrap.h" -#include -#include +#include "stdlib/math/base/napi/ternary.h" -/** -* Receives JavaScript callback invocation data. -* -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - napi_status status; - - // Get callback arguments: - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); - assert( status == napi_ok ); - - // Check whether we were provided the correct number of arguments: - if ( argc < 3 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." ); - assert( status == napi_ok ); - return NULL; - } - if ( argc > 3 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." ); - 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 ( vtype0 != 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 ( vtype0 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - double v; - status = napi_get_value_double( env, argv[ 0 ], &v ); - assert( status == napi_ok ); - - double min; - status = napi_get_value_double( env, argv[ 1 ], &min ); - assert( status == napi_ok ); - - double max; - status = napi_get_value_double( env, argv[ 2 ], &max ); - assert( status == napi_ok ); - - double out = stdlib_base_wrap( v, min, max ); - - napi_value w; - status = napi_create_double( env, out, &w ); - assert( status == napi_ok ); - - return w; -} - -/** -* Initializes a Node-API module. -* -* @param env environment under which the function is invoked -* @param exports exports object -* @return main export -*/ -static napi_value init( napi_env env, napi_value exports ) { - napi_value fcn; - napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; -} - -NAPI_MODULE( NODE_GYP_MODULE_NAME, init ) +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_wrap ) diff --git a/lib/node_modules/@stdlib/math/base/special/wrap/src/main.c b/lib/node_modules/@stdlib/math/base/special/wrap/src/main.c index df46f5f9f30c..59fccb638f69 100644 --- a/lib/node_modules/@stdlib/math/base/special/wrap/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/wrap/src/main.c @@ -19,9 +19,8 @@ #include "stdlib/math/base/special/wrap.h" #include "stdlib/math/base/assert/is_nan.h" #include "stdlib/math/base/special/trunc.h" -#include - -// TODO: remove header and fmod once we have stdlib equivalent +#include "stdlib/math/base/special/fmod.h" +#include "stdlib/math/base/assert/is_negative_zero.h" /** * Wraps a value on the half-open interval [min,max). @@ -49,13 +48,13 @@ double stdlib_base_wrap( const double v, const double min, const double max ) { vc = v; // Normalize +-0 to +0... - if ( vc == 0.0 ) { + if ( stdlib_base_is_negative_zero( vc ) ) { vc = 0.0; } - if ( minc == 0.0 ) { + if ( stdlib_base_is_negative_zero( minc ) ) { minc = 0.0; } - if ( maxc == 0.0 ) { + if ( stdlib_base_is_negative_zero( maxc ) ) { maxc = 0.0; } // Simple case where value is already within range... @@ -67,5 +66,5 @@ double stdlib_base_wrap( const double v, const double min, const double max ) { if ( vc < minc ) { vc += delta * ( stdlib_base_trunc( ( minc - vc ) / delta ) + 1.0 ); } - return minc + ( fmod( vc - minc, delta ) ); + return minc + ( stdlib_base_fmod( vc - minc, delta ) ); }