Skip to content

refactor: move implementations and macros to separate files #5544

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

Merged
merged 2 commits into from
Mar 1, 2025
Merged
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
500 changes: 251 additions & 249 deletions lib/node_modules/@stdlib/math/base/napi/unary/README.md

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* @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.
*/

#ifndef STDLIB_MATH_BASE_NAPI_UNARY_C_C_H
#define STDLIB_MATH_BASE_NAPI_UNARY_C_C_H

#include "stdlib/complex/float32/ctor.h"
#include <node_api.h>
#include <assert.h>

/**
* Macro for registering a Node-API module exporting an interface invoking a unary function accepting and returning single-precision complex floating-point numbers.
*
* @param fcn unary function
*
* @example
* #include "stdlib/complex/float32/ctor.h"
* #include "stdlib/complex/float32/reim.h"
*
* static stdlib_complex64_t scale( const stdlib_complex64_t x ) {
* float re;
* float im;
*
* stdlib_complex64_reim( x, &re, &im );
*
* re *= 10.0f;
* im *= 10.0f;
*
* return stdlib_complex64( re, im );
* }
*
* // ...
*
* // Register a Node-API module:
* STDLIB_MATH_BASE_NAPI_MODULE_C_C( scale );
*/
#define STDLIB_MATH_BASE_NAPI_MODULE_C_C( fcn ) \
static napi_value stdlib_math_base_napi_c_c_wrapper( \
napi_env env, \
napi_callback_info info \
) { \
return stdlib_math_base_napi_c_c( env, info, fcn ); \
}; \
static napi_value stdlib_math_base_napi_c_c_init( \
napi_env env, \
napi_value exports \
) { \
napi_value fcn; \
napi_status status = napi_create_function( \
env, \
"exports", \
NAPI_AUTO_LENGTH, \
stdlib_math_base_napi_c_c_wrapper, \
NULL, \
&fcn \
); \
assert( status == napi_ok ); \
return fcn; \
}; \
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_c_c_init )

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
#ifdef __cplusplus
extern "C" {
#endif

/**
* Invokes a unary function accepting and returning single-precision complex floating-point numbers.
*/
napi_value stdlib_math_base_napi_c_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t ) );

#ifdef __cplusplus
}
#endif

#endif // !STDLIB_MATH_BASE_NAPI_UNARY_C_C_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* @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.
*/

#ifndef STDLIB_MATH_BASE_NAPI_UNARY_C_F_H
#define STDLIB_MATH_BASE_NAPI_UNARY_C_F_H

#include "stdlib/complex/float32/ctor.h"
#include <node_api.h>
#include <assert.h>

/**
* 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.
*
* @param fcn unary function
*
* @example
* #include "stdlib/complex/float32/ctor.h"
*
* static float fcn( const stdlib_complex64_t x ) {
* // ...
* }
*
* // ...
*
* // Register a Node-API module:
* STDLIB_MATH_BASE_NAPI_MODULE_C_F( fcn );
*/
#define STDLIB_MATH_BASE_NAPI_MODULE_C_F( fcn ) \
static napi_value stdlib_math_base_napi_c_f_wrapper( \
napi_env env, \
napi_callback_info info \
) { \
return stdlib_math_base_napi_c_f( env, info, fcn ); \
}; \
static napi_value stdlib_math_base_napi_c_f_init( \
napi_env env, \
napi_value exports \
) { \
napi_value fcn; \
napi_status status = napi_create_function( \
env, \
"exports", \
NAPI_AUTO_LENGTH, \
stdlib_math_base_napi_c_f_wrapper, \
NULL, \
&fcn \
); \
assert( status == napi_ok ); \
return fcn; \
}; \
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_c_f_init )

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
#ifdef __cplusplus
extern "C" {
#endif

/**
* Invokes a unary function accepting a single-precision complex floating-point number and returning a single-precision floating-point number.
*/
napi_value stdlib_math_base_napi_c_f( napi_env env, napi_callback_info info, float (*fcn)( stdlib_complex64_t ) );

#ifdef __cplusplus
}
#endif

#endif // !STDLIB_MATH_BASE_NAPI_UNARY_C_F_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* @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.
*/

#ifndef STDLIB_MATH_BASE_NAPI_UNARY_D_D_H
#define STDLIB_MATH_BASE_NAPI_UNARY_D_D_H

#include <node_api.h>
#include <assert.h>

/**
* Macro for registering a Node-API module exporting an interface invoking a unary function accepting and returning double-precision floating-point numbers.
*
* @param fcn unary function
*
* @example
* static double scale( const double x ) {
* return x * 10.0;
* }
*
* // ...
*
* // Register a Node-API module:
* STDLIB_MATH_BASE_NAPI_MODULE_D_D( scale );
*/
#define STDLIB_MATH_BASE_NAPI_MODULE_D_D( fcn ) \
static napi_value stdlib_math_base_napi_d_d_wrapper( \
napi_env env, \
napi_callback_info info \
) { \
return stdlib_math_base_napi_d_d( env, info, fcn ); \
}; \
static napi_value stdlib_math_base_napi_d_d_init( \
napi_env env, \
napi_value exports \
) { \
napi_value fcn; \
napi_status status = napi_create_function( \
env, \
"exports", \
NAPI_AUTO_LENGTH, \
stdlib_math_base_napi_d_d_wrapper, \
NULL, \
&fcn \
); \
assert( status == napi_ok ); \
return fcn; \
}; \
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_d_d_init )

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
#ifdef __cplusplus
extern "C" {
#endif

/**
* Invokes a unary function accepting and returning double-precision floating-point numbers.
*/
napi_value stdlib_math_base_napi_d_d( napi_env env, napi_callback_info info, double (*fcn)( double ) );

#ifdef __cplusplus
}
#endif

#endif // !STDLIB_MATH_BASE_NAPI_UNARY_D_D_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* @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.
*/

#ifndef STDLIB_MATH_BASE_NAPI_UNARY_F_F_H
#define STDLIB_MATH_BASE_NAPI_UNARY_F_F_H

#include <node_api.h>
#include <assert.h>

/**
* Macro for registering a Node-API module exporting an interface invoking a unary function accepting and returning single-precision floating-point numbers.
*
* @param fcn unary function
*
* @example
* static float scale( const float x ) {
* return x * 10.0f;
* }
*
* // ...
*
* // Register a Node-API module:
* STDLIB_MATH_BASE_NAPI_MODULE_F_F( scale );
*/
#define STDLIB_MATH_BASE_NAPI_MODULE_F_F( fcn ) \
static napi_value stdlib_math_base_napi_f_f_wrapper( \
napi_env env, \
napi_callback_info info \
) { \
return stdlib_math_base_napi_f_f( env, info, fcn ); \
}; \
static napi_value stdlib_math_base_napi_f_f_init( \
napi_env env, \
napi_value exports \
) { \
napi_value fcn; \
napi_status status = napi_create_function( \
env, \
"exports", \
NAPI_AUTO_LENGTH, \
stdlib_math_base_napi_f_f_wrapper, \
NULL, \
&fcn \
); \
assert( status == napi_ok ); \
return fcn; \
}; \
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_f_f_init )

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
#ifdef __cplusplus
extern "C" {
#endif

/**
* Invokes a unary function accepting and returning single-precision floating-point numbers.
*/
napi_value stdlib_math_base_napi_f_f( napi_env env, napi_callback_info info, float (*fcn)( float ) );

#ifdef __cplusplus
}
#endif

#endif // !STDLIB_MATH_BASE_NAPI_UNARY_F_F_H
Loading