Skip to content

refactor: move implementations and macros to separate files #5541

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 1 commit 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
86 changes: 44 additions & 42 deletions lib/node_modules/@stdlib/math/base/napi/quinary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ console.log( headerDir );
#include "stdlib/math/base/napi/quinary.h"
```

<!-- NOTE: keep in alphabetical order according to the suffix XXXXX_X -->

#### STDLIB_MATH_BASE_NAPI_MODULE_DDDDD_D( fcn )

Macro for registering a Node-API module exporting an interface for invoking a quinary function accepting and returning double-precision floating-point numbers.

```c
static double add( const double x, const double y, const double z, const double w, const double u ) {
return x + y + z + w + u;
}

// ...

// Register a Node-API module:
STDLIB_MATH_BASE_NAPI_MODULE_DDDDD_D( add );
```

The macro expects the following arguments:

- **fcn**: `double (*fcn)( double, double, double, double, double )` quinary function.

When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.

#### stdlib_math_base_napi_ddddd_d( env, info, fcn )

Invokes a quinary function accepting and returning double-precision floating-point numbers.
Expand Down Expand Up @@ -143,6 +166,27 @@ The function accepts the following arguments:
void stdlib_math_base_napi_ddddd_d( napi_env env, napi_callback_info info, double (*fcn)( double, double, double, double, double ) );
```

#### STDLIB_MATH_BASE_NAPI_MODULE_FFFFF_F( fcn )

Macro for registering a Node-API module exporting an interface for invoking a quinary function accepting and returning single-precision floating-point numbers.

```c
static float addf( const float x, const float y, const float z, const float w, const float u ) {
return x + y + z + w + u;
}

// ...

// Register a Node-API module:
STDLIB_MATH_BASE_NAPI_MODULE_FFFFF_F( addf );
```

The macro expects the following arguments:

- **fcn**: `float (*fcn)( float, float, float, float, float )` quinary function.

When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.

#### stdlib_math_base_napi_fffff_f( env, info, fcn )

Invokes a quinary function accepting and returning single-precision floating-point numbers.
Expand Down Expand Up @@ -182,48 +226,6 @@ The function accepts the following arguments:
void stdlib_math_base_napi_fffff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float, float, float, float ) );
```

#### STDLIB_MATH_BASE_NAPI_MODULE_DDDDD_D( fcn )

Macro for registering a Node-API module exporting an interface for invoking a quinary function accepting and returning double-precision floating-point numbers.

```c
static double add( const double x, const double y, const double z, const double w, const double u ) {
return x + y + z + w + u;
}

// ...

// Register a Node-API module:
STDLIB_MATH_BASE_NAPI_MODULE_DDDDD_D( add );
```

The macro expects the following arguments:

- **fcn**: `double (*fcn)( double, double, double, double, double )` quinary function.

When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.

#### STDLIB_MATH_BASE_NAPI_MODULE_FFFFF_F( fcn )

Macro for registering a Node-API module exporting an interface for invoking a quinary function accepting and returning single-precision floating-point numbers.

```c
static float addf( const float x, const float y, const float z, const float w, const float u ) {
return x + y + z + w + u;
}

// ...

// Register a Node-API module:
STDLIB_MATH_BASE_NAPI_MODULE_FFFFF_F( addf );
```

The macro expects the following arguments:

- **fcn**: `float (*fcn)( float, float, float, float, float )` quinary function.

When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.

</section>

<!-- /.usage -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,105 +22,8 @@
#include <node_api.h>
#include <assert.h>

/**
* Macro for registering a Node-API module exporting an interface invoking a quinary function accepting and returning double-precision floating-point numbers.
*
* @param fcn quinary function
*
* @example
* static double add( const double x, const double y, const double z, const double w, const double u ) {
* return x + y + z + w + u;
* }
*
* // ...
*
* // Register a Node-API module:
* STDLIB_MATH_BASE_NAPI_MODULE_DDDDD_D( add );
*/
#define STDLIB_MATH_BASE_NAPI_MODULE_DDDDD_D( fcn ) \
static napi_value stdlib_math_base_napi_ddddd_d_wrapper( \
napi_env env, \
napi_callback_info info \
) { \
return stdlib_math_base_napi_ddddd_d( env, info, fcn ); \
}; \
static napi_value stdlib_math_base_napi_ddddd_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_ddddd_d_wrapper, \
NULL, \
&fcn \
); \
assert( status == napi_ok ); \
return fcn; \
}; \
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_ddddd_d_init )

/**
* Macro for registering a Node-API module exporting an interface invoking a quinary function accepting and returning single-precision floating-point numbers.
*
* @param fcn quinary function
*
* @example
* static float addf( const float x, const float y, const float z, const float w, const float u ) {
* return x + y + z + w + u;
* }
*
* // ...
*
* // Register a Node-API module:
* STDLIB_MATH_BASE_NAPI_MODULE_FFFFF_F( addf );
*/
#define STDLIB_MATH_BASE_NAPI_MODULE_FFFFF_F( fcn ) \
static napi_value stdlib_math_base_napi_fffff_f_wrapper( \
napi_env env, \
napi_callback_info info \
) { \
return stdlib_math_base_napi_fffff_f( env, info, fcn ); \
}; \
static napi_value stdlib_math_base_napi_fffff_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_fffff_f_wrapper, \
NULL, \
&fcn \
); \
assert( status == napi_ok ); \
return fcn; \
}; \
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_fffff_f_init )

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

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

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

#ifdef __cplusplus
}
#endif
// NOTE: keep in alphabetical order...
#include "stdlib/math/base/napi/quinary/ddddd_d.h"
#include "stdlib/math/base/napi/quinary/fffff_f.h"

#endif // !STDLIB_MATH_BASE_NAPI_QUINARY_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_QUINARY_DDDDD_D_H
#define STDLIB_MATH_BASE_NAPI_QUINARY_DDDDD_D_H

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

/**
* Macro for registering a Node-API module exporting an interface invoking a quinary function accepting and returning double-precision floating-point numbers.
*
* @param fcn quinary function
*
* @example
* static double add( const double x, const double y, const double z, const double w, const double u ) {
* return x + y + z + w + u;
* }
*
* // ...
*
* // Register a Node-API module:
* STDLIB_MATH_BASE_NAPI_MODULE_DDDDD_D( add );
*/
#define STDLIB_MATH_BASE_NAPI_MODULE_DDDDD_D( fcn ) \
static napi_value stdlib_math_base_napi_ddddd_d_wrapper( \
napi_env env, \
napi_callback_info info \
) { \
return stdlib_math_base_napi_ddddd_d( env, info, fcn ); \
}; \
static napi_value stdlib_math_base_napi_ddddd_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_ddddd_d_wrapper, \
NULL, \
&fcn \
); \
assert( status == napi_ok ); \
return fcn; \
}; \
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_ddddd_d_init )

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

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

#ifdef __cplusplus
}
#endif

#endif // !STDLIB_MATH_BASE_NAPI_QUINARY_DDDDD_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_QUINARY_FFFFF_F_H
#define STDLIB_MATH_BASE_NAPI_QUINARY_FFFFF_F_H

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

/**
* Macro for registering a Node-API module exporting an interface invoking a quinary function accepting and returning single-precision floating-point numbers.
*
* @param fcn quinary function
*
* @example
* static float addf( const float x, const float y, const float z, const float w, const float u ) {
* return x + y + z + w + u;
* }
*
* // ...
*
* // Register a Node-API module:
* STDLIB_MATH_BASE_NAPI_MODULE_FFFFF_F( addf );
*/
#define STDLIB_MATH_BASE_NAPI_MODULE_FFFFF_F( fcn ) \
static napi_value stdlib_math_base_napi_fffff_f_wrapper( \
napi_env env, \
napi_callback_info info \
) { \
return stdlib_math_base_napi_fffff_f( env, info, fcn ); \
}; \
static napi_value stdlib_math_base_napi_fffff_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_fffff_f_wrapper, \
NULL, \
&fcn \
); \
assert( status == napi_ok ); \
return fcn; \
}; \
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_fffff_f_init )

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

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

#ifdef __cplusplus
}
#endif

#endif // !STDLIB_MATH_BASE_NAPI_QUINARY_FFFFF_F_H
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"confs": [
{
"src": [
"./src/main.c"
"./src/ddddd_d.c",
"./src/fffff_f.c"
],
"include": [
"./include"
Expand Down
Loading