Skip to content

Commit

Permalink
refactor: update math/base/assert/is-finite native addon from C++ to C
Browse files Browse the repository at this point in the history
PR-URL: stdlib-js#4617
Reviewed-by: Athan Reines <[email protected]>
Co-authored-by: stdlib-bot <[email protected]>
  • Loading branch information
2 people authored and Vinit-Pandit committed Feb 4, 2025
1 parent 65cd03e commit 2a0bb5d
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Source files:
'src_files': [
'<(src_dir)/addon.cpp',
'<(src_dir)/addon.c',
'<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
],

Expand Down
108 changes: 70 additions & 38 deletions lib/node_modules/@stdlib/math/base/assert/is-finite/manifest.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,72 @@
{
"options": {},
"fields": [
{
"field": "src",
"resolve": true,
"relative": true
},
{
"field": "include",
"resolve": true,
"relative": true
},
{
"field": "libraries",
"resolve": false,
"relative": false
},
{
"field": "libpath",
"resolve": true,
"relative": false
}
],
"confs": [
{
"src": [
"./src/is_finite.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": []
}
]
"options": {
"task": "build"
},
"fields": [
{
"field": "src",
"resolve": true,
"relative": true
},
{
"field": "include",
"resolve": true,
"relative": true
},
{
"field": "libraries",
"resolve": false,
"relative": false
},
{
"field": "libpath",
"resolve": true,
"relative": false
}
],
"confs": [
{
"task": "build",
"src": [
"./src/is_finite.c"
],
"include": [
"./include"
],
"libraries": [
"-lm"
],
"libpath": [],
"dependencies": [
"@stdlib/napi/export",
"@stdlib/napi/argv",
"@stdlib/napi/argv-double",
"@stdlib/napi/create-int32"
]
},
{
"task": "benchmark",
"src": [
"./src/is_finite.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": []
},
{
"task": "examples",
"src": [
"./src/is_finite.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": []
}
]
}
42 changes: 42 additions & 0 deletions lib/node_modules/@stdlib/math/base/assert/is-finite/src/addon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "stdlib/math/base/assert/is_finite.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>

/**
* 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 ) {
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_finite( x ), out );
return out;
}

STDLIB_NAPI_MODULE_EXPORT_FCN( addon )

80 changes: 0 additions & 80 deletions lib/node_modules/@stdlib/math/base/assert/is-finite/src/addon.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,3 @@ tape( 'the function returns `false` if provided `-infinity`', opts, function tes
t.equal( isfinite( NINF ), false, 'returns false' );
t.end();
});

tape( 'the function returns `false` if not provided a finite number', opts, function test( t ) {
var values;
var i;

values = [
'5',
NaN,
true,
null,
void 0,
[],
{},
function noop() {}
];

for ( i = 0; i < values.length; i++ ) {
t.equal( isfinite( values[i] ), false, 'returns false' );
}
t.end();
});

0 comments on commit 2a0bb5d

Please sign in to comment.