Skip to content

Commit 452ba64

Browse files
refactor: update math/base/assert/is-integerf to follow latest project conventions
PR-URL: #4629 Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 50843c9 commit 452ba64

File tree

3 files changed

+55
-60
lines changed

3 files changed

+55
-60
lines changed

lib/node_modules/@stdlib/math/base/assert/is-integerf/benchmark/c/native/benchmark.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,17 @@ static float rand_float( void ) {
9393
static double benchmark( void ) {
9494
double elapsed;
9595
double t;
96-
float x;
96+
float x[ 100 ];
9797
bool b;
9898
int i;
9999

100+
for ( i = 0; i < 100; i++ ) {
101+
x[ i ] = ( rand_float() * 1000.0f ) - 500.0f;
102+
}
103+
100104
t = tic();
101105
for ( i = 0; i < ITERATIONS; i++ ) {
102-
x = ( rand_float() * 1000.0f ) - 500.0f;
103-
b = stdlib_base_is_integerf( x );
106+
b = stdlib_base_is_integerf( x[ i%100 ] );
104107
if ( b != true && b != false ) {
105108
printf( "should return either true or false\n" );
106109
break;

lib/node_modules/@stdlib/math/base/assert/is-integerf/manifest.json

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"options": {},
2+
"options": {
3+
"task": "build"
4+
},
35
"fields": [
46
{
57
"field": "src",
@@ -24,6 +26,43 @@
2426
],
2527
"confs": [
2628
{
29+
"task": "build",
30+
"src": [
31+
"./src/main.c"
32+
],
33+
"include": [
34+
"./include"
35+
],
36+
"libraries": [
37+
"-lm"
38+
],
39+
"libpath": [],
40+
"dependencies": [
41+
"@stdlib/math/base/special/floorf",
42+
"@stdlib/napi/export",
43+
"@stdlib/napi/argv",
44+
"@stdlib/napi/argv-double",
45+
"@stdlib/napi/create-int32"
46+
]
47+
},
48+
{
49+
"task": "benchmark",
50+
"src": [
51+
"./src/main.c"
52+
],
53+
"include": [
54+
"./include"
55+
],
56+
"libraries": [
57+
"-lm"
58+
],
59+
"libpath": [],
60+
"dependencies": [
61+
"@stdlib/math/base/special/floorf"
62+
]
63+
},
64+
{
65+
"task": "examples",
2766
"src": [
2867
"./src/main.c"
2968
],

lib/node_modules/@stdlib/math/base/assert/is-integerf/src/addon.c

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
*/
1818

1919
#include "stdlib/math/base/assert/is_integerf.h"
20+
#include "stdlib/napi/argv.h"
21+
#include "stdlib/napi/argv_double.h"
22+
#include "stdlib/napi/create_int32.h"
23+
#include "stdlib/napi/export.h"
2024
#include <node_api.h>
2125
#include <stdint.h>
22-
#include <assert.h>
2326

2427
/**
2528
* Receives JavaScript callback invocation data.
@@ -29,60 +32,10 @@
2932
* @return Node-API value
3033
*/
3134
static napi_value addon( napi_env env, napi_callback_info info ) {
32-
napi_status status;
33-
34-
// Get callback arguments:
35-
size_t argc = 1;
36-
napi_value argv[ 1 ];
37-
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
38-
assert( status == napi_ok );
39-
40-
// Check whether we were provided the correct number of arguments:
41-
if ( argc < 1 ) {
42-
status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." );
43-
assert( status == napi_ok );
44-
return NULL;
45-
}
46-
if ( argc > 1 ) {
47-
status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." );
48-
assert( status == napi_ok );
49-
return NULL;
50-
}
51-
52-
napi_valuetype vtype0;
53-
status = napi_typeof( env, argv[ 0 ], &vtype0 );
54-
assert( status == napi_ok );
55-
if ( vtype0 != napi_number ) {
56-
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
57-
assert( status == napi_ok );
58-
return NULL;
59-
}
60-
61-
double x;
62-
status = napi_get_value_double( env, argv[ 0 ], &x );
63-
assert( status == napi_ok );
64-
65-
bool result = stdlib_base_is_integerf( (float)x );
66-
67-
napi_value v;
68-
status = napi_create_int32( env, (int32_t)result, &v );
69-
assert( status == napi_ok );
70-
71-
return v;
72-
}
73-
74-
/**
75-
* Initializes a Node-API module.
76-
*
77-
* @param env environment under which the function is invoked
78-
* @param exports exports object
79-
* @return main export
80-
*/
81-
static napi_value init( napi_env env, napi_value exports ) {
82-
napi_value fcn;
83-
napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn );
84-
assert( status == napi_ok );
85-
return fcn;
35+
STDLIB_NAPI_ARGV( env, info, argv, argc, 1 );
36+
STDLIB_NAPI_ARGV_DOUBLE( env, x, argv, 0 );
37+
STDLIB_NAPI_CREATE_INT32( env, (int32_t)stdlib_base_is_integerf( (float)x ), out );
38+
return out;
8639
}
8740

88-
NAPI_MODULE( NODE_GYP_MODULE_NAME, init )
41+
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )

0 commit comments

Comments
 (0)