Skip to content

Commit b2c926b

Browse files
refactor: move implementations and macros to separate files
PR-URL: #5544 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 183d056 commit b2c926b

File tree

24 files changed

+2018
-1447
lines changed

24 files changed

+2018
-1447
lines changed

lib/node_modules/@stdlib/math/base/napi/unary/README.md

Lines changed: 251 additions & 249 deletions
Large diffs are not rendered by default.

lib/node_modules/@stdlib/math/base/napi/unary/include/stdlib/math/base/napi/unary.h

Lines changed: 11 additions & 500 deletions
Large diffs are not rendered by default.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
#ifndef STDLIB_MATH_BASE_NAPI_UNARY_C_C_H
20+
#define STDLIB_MATH_BASE_NAPI_UNARY_C_C_H
21+
22+
#include "stdlib/complex/float32/ctor.h"
23+
#include <node_api.h>
24+
#include <assert.h>
25+
26+
/**
27+
* Macro for registering a Node-API module exporting an interface invoking a unary function accepting and returning single-precision complex floating-point numbers.
28+
*
29+
* @param fcn unary function
30+
*
31+
* @example
32+
* #include "stdlib/complex/float32/ctor.h"
33+
* #include "stdlib/complex/float32/reim.h"
34+
*
35+
* static stdlib_complex64_t scale( const stdlib_complex64_t x ) {
36+
* float re;
37+
* float im;
38+
*
39+
* stdlib_complex64_reim( x, &re, &im );
40+
*
41+
* re *= 10.0f;
42+
* im *= 10.0f;
43+
*
44+
* return stdlib_complex64( re, im );
45+
* }
46+
*
47+
* // ...
48+
*
49+
* // Register a Node-API module:
50+
* STDLIB_MATH_BASE_NAPI_MODULE_C_C( scale );
51+
*/
52+
#define STDLIB_MATH_BASE_NAPI_MODULE_C_C( fcn ) \
53+
static napi_value stdlib_math_base_napi_c_c_wrapper( \
54+
napi_env env, \
55+
napi_callback_info info \
56+
) { \
57+
return stdlib_math_base_napi_c_c( env, info, fcn ); \
58+
}; \
59+
static napi_value stdlib_math_base_napi_c_c_init( \
60+
napi_env env, \
61+
napi_value exports \
62+
) { \
63+
napi_value fcn; \
64+
napi_status status = napi_create_function( \
65+
env, \
66+
"exports", \
67+
NAPI_AUTO_LENGTH, \
68+
stdlib_math_base_napi_c_c_wrapper, \
69+
NULL, \
70+
&fcn \
71+
); \
72+
assert( status == napi_ok ); \
73+
return fcn; \
74+
}; \
75+
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_c_c_init )
76+
77+
/*
78+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
79+
*/
80+
#ifdef __cplusplus
81+
extern "C" {
82+
#endif
83+
84+
/**
85+
* Invokes a unary function accepting and returning single-precision complex floating-point numbers.
86+
*/
87+
napi_value stdlib_math_base_napi_c_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t ) );
88+
89+
#ifdef __cplusplus
90+
}
91+
#endif
92+
93+
#endif // !STDLIB_MATH_BASE_NAPI_UNARY_C_C_H
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
#ifndef STDLIB_MATH_BASE_NAPI_UNARY_C_F_H
20+
#define STDLIB_MATH_BASE_NAPI_UNARY_C_F_H
21+
22+
#include "stdlib/complex/float32/ctor.h"
23+
#include <node_api.h>
24+
#include <assert.h>
25+
26+
/**
27+
* Macro for registering a Node-API module exporting an interface invoking a unary function accepting a single-precision complex floating-point number and returning a single-precision floating-point number.
28+
*
29+
* @param fcn unary function
30+
*
31+
* @example
32+
* #include "stdlib/complex/float32/ctor.h"
33+
*
34+
* static float fcn( const stdlib_complex64_t x ) {
35+
* // ...
36+
* }
37+
*
38+
* // ...
39+
*
40+
* // Register a Node-API module:
41+
* STDLIB_MATH_BASE_NAPI_MODULE_C_F( fcn );
42+
*/
43+
#define STDLIB_MATH_BASE_NAPI_MODULE_C_F( fcn ) \
44+
static napi_value stdlib_math_base_napi_c_f_wrapper( \
45+
napi_env env, \
46+
napi_callback_info info \
47+
) { \
48+
return stdlib_math_base_napi_c_f( env, info, fcn ); \
49+
}; \
50+
static napi_value stdlib_math_base_napi_c_f_init( \
51+
napi_env env, \
52+
napi_value exports \
53+
) { \
54+
napi_value fcn; \
55+
napi_status status = napi_create_function( \
56+
env, \
57+
"exports", \
58+
NAPI_AUTO_LENGTH, \
59+
stdlib_math_base_napi_c_f_wrapper, \
60+
NULL, \
61+
&fcn \
62+
); \
63+
assert( status == napi_ok ); \
64+
return fcn; \
65+
}; \
66+
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_c_f_init )
67+
68+
/*
69+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
70+
*/
71+
#ifdef __cplusplus
72+
extern "C" {
73+
#endif
74+
75+
/**
76+
* Invokes a unary function accepting a single-precision complex floating-point number and returning a single-precision floating-point number.
77+
*/
78+
napi_value stdlib_math_base_napi_c_f( napi_env env, napi_callback_info info, float (*fcn)( stdlib_complex64_t ) );
79+
80+
#ifdef __cplusplus
81+
}
82+
#endif
83+
84+
#endif // !STDLIB_MATH_BASE_NAPI_UNARY_C_F_H
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
#ifndef STDLIB_MATH_BASE_NAPI_UNARY_D_D_H
20+
#define STDLIB_MATH_BASE_NAPI_UNARY_D_D_H
21+
22+
#include <node_api.h>
23+
#include <assert.h>
24+
25+
/**
26+
* Macro for registering a Node-API module exporting an interface invoking a unary function accepting and returning double-precision floating-point numbers.
27+
*
28+
* @param fcn unary function
29+
*
30+
* @example
31+
* static double scale( const double x ) {
32+
* return x * 10.0;
33+
* }
34+
*
35+
* // ...
36+
*
37+
* // Register a Node-API module:
38+
* STDLIB_MATH_BASE_NAPI_MODULE_D_D( scale );
39+
*/
40+
#define STDLIB_MATH_BASE_NAPI_MODULE_D_D( fcn ) \
41+
static napi_value stdlib_math_base_napi_d_d_wrapper( \
42+
napi_env env, \
43+
napi_callback_info info \
44+
) { \
45+
return stdlib_math_base_napi_d_d( env, info, fcn ); \
46+
}; \
47+
static napi_value stdlib_math_base_napi_d_d_init( \
48+
napi_env env, \
49+
napi_value exports \
50+
) { \
51+
napi_value fcn; \
52+
napi_status status = napi_create_function( \
53+
env, \
54+
"exports", \
55+
NAPI_AUTO_LENGTH, \
56+
stdlib_math_base_napi_d_d_wrapper, \
57+
NULL, \
58+
&fcn \
59+
); \
60+
assert( status == napi_ok ); \
61+
return fcn; \
62+
}; \
63+
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_d_d_init )
64+
65+
/*
66+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
67+
*/
68+
#ifdef __cplusplus
69+
extern "C" {
70+
#endif
71+
72+
/**
73+
* Invokes a unary function accepting and returning double-precision floating-point numbers.
74+
*/
75+
napi_value stdlib_math_base_napi_d_d( napi_env env, napi_callback_info info, double (*fcn)( double ) );
76+
77+
#ifdef __cplusplus
78+
}
79+
#endif
80+
81+
#endif // !STDLIB_MATH_BASE_NAPI_UNARY_D_D_H
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
#ifndef STDLIB_MATH_BASE_NAPI_UNARY_F_F_H
20+
#define STDLIB_MATH_BASE_NAPI_UNARY_F_F_H
21+
22+
#include <node_api.h>
23+
#include <assert.h>
24+
25+
/**
26+
* Macro for registering a Node-API module exporting an interface invoking a unary function accepting and returning single-precision floating-point numbers.
27+
*
28+
* @param fcn unary function
29+
*
30+
* @example
31+
* static float scale( const float x ) {
32+
* return x * 10.0f;
33+
* }
34+
*
35+
* // ...
36+
*
37+
* // Register a Node-API module:
38+
* STDLIB_MATH_BASE_NAPI_MODULE_F_F( scale );
39+
*/
40+
#define STDLIB_MATH_BASE_NAPI_MODULE_F_F( fcn ) \
41+
static napi_value stdlib_math_base_napi_f_f_wrapper( \
42+
napi_env env, \
43+
napi_callback_info info \
44+
) { \
45+
return stdlib_math_base_napi_f_f( env, info, fcn ); \
46+
}; \
47+
static napi_value stdlib_math_base_napi_f_f_init( \
48+
napi_env env, \
49+
napi_value exports \
50+
) { \
51+
napi_value fcn; \
52+
napi_status status = napi_create_function( \
53+
env, \
54+
"exports", \
55+
NAPI_AUTO_LENGTH, \
56+
stdlib_math_base_napi_f_f_wrapper, \
57+
NULL, \
58+
&fcn \
59+
); \
60+
assert( status == napi_ok ); \
61+
return fcn; \
62+
}; \
63+
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_f_f_init )
64+
65+
/*
66+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
67+
*/
68+
#ifdef __cplusplus
69+
extern "C" {
70+
#endif
71+
72+
/**
73+
* Invokes a unary function accepting and returning single-precision floating-point numbers.
74+
*/
75+
napi_value stdlib_math_base_napi_f_f( napi_env env, napi_callback_info info, float (*fcn)( float ) );
76+
77+
#ifdef __cplusplus
78+
}
79+
#endif
80+
81+
#endif // !STDLIB_MATH_BASE_NAPI_UNARY_F_F_H

0 commit comments

Comments
 (0)