Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update math/base/assert/is-integer to follow latest project conventions #4627

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"options": {},
"options": {
"task": "build"
},
"fields": [
{
"field": "src",
Expand All @@ -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"
],
Expand Down
65 changes: 9 additions & 56 deletions lib/node_modules/@stdlib/math/base/assert/is-integer/src/addon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <node_api.h>
#include <stdint.h>
#include <assert.h>

/**
* Receives JavaScript callback invocation data.
Expand All @@ -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 )
Loading