Skip to content

Commit 60983a6

Browse files
DhruvArvindSinghkgrytestdlib-bot
authored
refactor: update math/base/assert/is-finitef native addon from C++ to C
PR-URL: #4618 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Co-authored-by: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com>
1 parent dda206d commit 60983a6

File tree

5 files changed

+113
-140
lines changed

5 files changed

+113
-140
lines changed

lib/node_modules/@stdlib/math/base/assert/is-finitef/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 & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +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_finitef.c"
29-
],
30-
"include": [
31-
"./include"
32-
],
33-
"libraries": [
34-
"-lm"
35-
],
36-
"libpath": [],
37-
"dependencies": []
38-
}
39-
]
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_finitef.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_finitef.c"
51+
],
52+
"include": [
53+
"./include"
54+
],
55+
"libraries": [],
56+
"libpath": [],
57+
"dependencies": []
58+
},
59+
{
60+
"task": "examples",
61+
"src": [
62+
"./src/is_finitef.c"
63+
],
64+
"include": [
65+
"./include"
66+
],
67+
"libraries": [],
68+
"libpath": [],
69+
"dependencies": []
70+
}
71+
]
4072
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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_finitef.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_finitef( x ), out );
38+
return out;
39+
}
40+
41+
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
42+

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

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

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,3 @@ tape( 'the function returns `false` if provided `-infinity`', opts, function tes
7474
t.equal( isfinitef( NINF ), false, 'returns false' );
7575
t.end();
7676
});
77-
78-
tape( 'the function returns `false` if not provided a finite number', opts, function test( t ) {
79-
var values;
80-
var i;
81-
82-
values = [
83-
'5',
84-
NaN,
85-
true,
86-
null,
87-
void 0,
88-
[],
89-
{},
90-
function noop() {}
91-
];
92-
93-
for ( i = 0; i < values.length; i++ ) {
94-
t.equal( isfinitef( values[i] ), false, 'returns false' );
95-
}
96-
t.end();
97-
});

0 commit comments

Comments
 (0)