Skip to content

Commit dda206d

Browse files
refactor: update math/base/assert/is-nanf native addon from C++ to C
PR-URL: #4614 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 566ff63 commit dda206d

File tree

5 files changed

+112
-141
lines changed

5 files changed

+112
-141
lines changed

lib/node_modules/@stdlib/math/base/assert/is-nanf/include.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Source files:
3838
'src_files': [
39-
'<(src_dir)/addon.cpp',
39+
'<(src_dir)/addon.c',
4040
'<!@(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 ] ); }")',
4141
],
4242

Lines changed: 70 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,72 @@
11
{
2-
"options": {},
3-
"fields": [
4-
{
5-
"field": "src",
6-
"resolve": true,
7-
"relative": true
8-
},
9-
{
10-
"field": "include",
11-
"resolve": true,
12-
"relative": true
13-
},
14-
{
15-
"field": "libraries",
16-
"resolve": false,
17-
"relative": false
18-
},
19-
{
20-
"field": "libpath",
21-
"resolve": true,
22-
"relative": false
23-
}
24-
],
25-
"confs": [
26-
{
27-
"src": [
28-
"./src/is_nanf.c"
29-
],
30-
"include": [
31-
"./include"
32-
],
33-
"libraries": [],
34-
"libpath": [],
35-
"dependencies": []
36-
}
37-
]
2+
"options": {
3+
"task": "build"
4+
},
5+
"fields": [
6+
{
7+
"field": "src",
8+
"resolve": true,
9+
"relative": true
10+
},
11+
{
12+
"field": "include",
13+
"resolve": true,
14+
"relative": true
15+
},
16+
{
17+
"field": "libraries",
18+
"resolve": false,
19+
"relative": false
20+
},
21+
{
22+
"field": "libpath",
23+
"resolve": true,
24+
"relative": false
25+
}
26+
],
27+
"confs": [
28+
{
29+
"task": "build",
30+
"src": [
31+
"./src/is_nanf.c"
32+
],
33+
"include": [
34+
"./include"
35+
],
36+
"libraries": [
37+
"-lm"
38+
],
39+
"libpath": [],
40+
"dependencies": [
41+
"@stdlib/napi/export",
42+
"@stdlib/napi/argv",
43+
"@stdlib/napi/argv-float",
44+
"@stdlib/napi/create-int32"
45+
]
46+
},
47+
{
48+
"task": "benchmark",
49+
"src": [
50+
"./src/is_nanf.c"
51+
],
52+
"include": [
53+
"./include"
54+
],
55+
"libraries": [],
56+
"libpath": [],
57+
"dependencies": []
58+
},
59+
{
60+
"task": "examples",
61+
"src": [
62+
"./src/is_nanf.c"
63+
],
64+
"include": [
65+
"./include"
66+
],
67+
"libraries": [],
68+
"libpath": [],
69+
"dependencies": []
70+
}
71+
]
3872
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "stdlib/math/base/assert/is_nanf.h"
20+
#include "stdlib/napi/argv.h"
21+
#include "stdlib/napi/argv_float.h"
22+
#include "stdlib/napi/create_int32.h"
23+
#include "stdlib/napi/export.h"
24+
#include <node_api.h>
25+
#include <stdint.h>
26+
27+
/**
28+
* Receives JavaScript callback invocation data.
29+
*
30+
* @param env environment under which the function is invoked
31+
* @param info callback data
32+
* @return Node-API value
33+
*/
34+
static napi_value addon( napi_env env, napi_callback_info info ) {
35+
STDLIB_NAPI_ARGV( env, info, argv, argc, 1 );
36+
STDLIB_NAPI_ARGV_FLOAT( env, x, argv, 0 );
37+
STDLIB_NAPI_CREATE_INT32( env, (int32_t)stdlib_base_is_nanf( x ), out );
38+
return out;
39+
}
40+
41+
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )

lib/node_modules/@stdlib/math/base/assert/is-nanf/src/addon.cpp

Lines changed: 0 additions & 80 deletions
This file was deleted.

lib/node_modules/@stdlib/math/base/assert/is-nanf/test/test.native.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
var resolve = require( 'path' ).resolve;
2424
var tape = require( 'tape' );
2525
var tryRequire = require( '@stdlib/utils/try-require' );
26-
var Number = require( '@stdlib/number/ctor' );
2726

2827

2928
// VARIABLES //
@@ -46,26 +45,3 @@ tape( 'the function returns `true` if provided `NaN`', opts, function test( t )
4645
t.equal( isnanf( NaN ), true, 'returns true' );
4746
t.end();
4847
});
49-
50-
tape( 'the function returns `false` if not provided `NaN`', opts, function test( t ) {
51-
var values;
52-
var i;
53-
54-
values = [
55-
'5',
56-
5.0,
57-
true,
58-
false,
59-
null,
60-
void 0,
61-
[],
62-
{},
63-
function noop() {},
64-
new Number( NaN ) // eslint-disable-line no-new-wrappers
65-
];
66-
67-
for ( i = 0; i < values.length; i++ ) {
68-
t.equal( isnanf( values[i] ), false, 'returns false when provided ' + values[ i ] );
69-
}
70-
t.end();
71-
});

0 commit comments

Comments
 (0)