From b01cb3f906e3e77633db6c901aa7c59f2fc63dbf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 19 Jan 2025 03:36:53 +0000 Subject: [PATCH] Auto-generated commit --- CHANGELOG.md | 1 + .../is-integer/benchmark/c/native/benchmark.c | 9 ++- base/assert/is-integer/manifest.json | 41 +++++++++++- base/assert/is-integer/src/addon.c | 65 +++---------------- 4 files changed, 56 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00e547ef9..3265e8c1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2877,6 +2877,7 @@ A total of 8 people contributed to this release. Thank you to the following cont
+- [`3129e35`](https://github.com/stdlib-js/stdlib/commit/3129e35d1daef24899fd03620f1bdd64d292cebd) - **refactor:** update `math/base/assert/is-integer` to follow latest project conventions [(#4627)](https://github.com/stdlib-js/stdlib/pull/4627) _(by Vivek Maurya)_ - [`452ba64`](https://github.com/stdlib-js/stdlib/commit/452ba64c898cec9c526ae2201aa149086347ec8e) - **refactor:** update `math/base/assert/is-integerf` to follow latest project conventions [(#4629)](https://github.com/stdlib-js/stdlib/pull/4629) _(by Vivek Maurya)_ - [`50843c9`](https://github.com/stdlib-js/stdlib/commit/50843c9502e3c9afa2f58d0957248e8ed3bd4609) - **docs:** update related packages sections [(#4808)](https://github.com/stdlib-js/stdlib/pull/4808) _(by stdlib-bot)_ - [`60983a6`](https://github.com/stdlib-js/stdlib/commit/60983a6b6946c48a3e38baeef28d19d76cbdb9c9) - **refactor:** update `math/base/assert/is-finitef` native addon from C++ to C [(#4618)](https://github.com/stdlib-js/stdlib/pull/4618) _(by Dhruv Arvind Singh, Athan Reines, stdlib-bot)_ diff --git a/base/assert/is-integer/benchmark/c/native/benchmark.c b/base/assert/is-integer/benchmark/c/native/benchmark.c index 8a2243155..c92c5e025 100644 --- a/base/assert/is-integer/benchmark/c/native/benchmark.c +++ b/base/assert/is-integer/benchmark/c/native/benchmark.c @@ -92,15 +92,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double x[ 100 ]; double t; bool b; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( rand_double() * 1000.0 ) - 500.0; + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( rand_double() * 1000.0 ) - 500.0; - b = stdlib_base_is_integer( x ); + b = stdlib_base_is_integer( x[ i%100 ] ); if ( b != true && b != false ) { printf( "should return either true or false\n" ); break; diff --git a/base/assert/is-integer/manifest.json b/base/assert/is-integer/manifest.json index e13af23df..e921a32c7 100644 --- a/base/assert/is-integer/manifest.json +++ b/base/assert/is-integer/manifest.json @@ -1,5 +1,7 @@ { - "options": {}, + "options": { + "task": "build" + }, "fields": [ { "field": "src", @@ -24,6 +26,43 @@ ], "confs": [ { + "task": "build", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/floor", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-double", + "@stdlib/napi/create-int32" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/floor" + ] + }, + { + "task": "examples", "src": [ "./src/main.c" ], diff --git a/base/assert/is-integer/src/addon.c b/base/assert/is-integer/src/addon.c index 27a1d2174..d69edb3c3 100644 --- a/base/assert/is-integer/src/addon.c +++ b/base/assert/is-integer/src/addon.c @@ -17,9 +17,12 @@ */ #include "stdlib/math/base/assert/is_integer.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_double.h" +#include "stdlib/napi/create_int32.h" +#include "stdlib/napi/export.h" #include #include -#include /** * Receives JavaScript callback invocation data. @@ -29,60 +32,10 @@ * @return Node-API value */ static napi_value addon( napi_env env, napi_callback_info info ) { - napi_status status; - - // Get callback arguments: - size_t argc = 1; - napi_value argv[ 1 ]; - 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 < 1 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." ); - assert( status == napi_ok ); - return NULL; - } - if ( argc > 1 ) { - 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; - } - - double x; - status = napi_get_value_double( env, argv[ 0 ], &x ); - assert( status == napi_ok ); - - bool result = stdlib_base_is_integer( x ); - - napi_value v; - status = napi_create_int32( env, (int32_t)result, &v ); - assert( status == napi_ok ); - - return v; -} - -/** -* 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; + STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ); + STDLIB_NAPI_ARGV_DOUBLE( env, x, argv, 0 ); + STDLIB_NAPI_CREATE_INT32( env, (int32_t)stdlib_base_is_integer( x ), out ); + return out; } -NAPI_MODULE( NODE_GYP_MODULE_NAME, init ) +STDLIB_NAPI_MODULE_EXPORT_FCN( addon )