Skip to content
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
103 changes: 103 additions & 0 deletions lib/node_modules/@stdlib/math/base/napi/quaternary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,109 @@ console.log( headerDir );

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

#### STDLIB_MATH_BASE_NAPI_MODULE_CCCC_C( fcn )

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

```c
#include "stdlib/complex/float32/ctor.h"
#include "stdlib/complex/float32/reim.h"

static stdlib_complex64_t add( const stdlib_complex64_t w, const stdlib_complex64_t x, const stdlib_complex64_t y, const stdlib_complex64_t z ) {
float wre;
float wim;
float xre;
float xim;
float yre;
float yim;
float zre;
float zim;
float re;
float im;

stdlib_complex64_reim( w, &wre, &wim );
stdlib_complex64_reim( x, &xre, &xim );
stdlib_complex64_reim( y, &yre, &yim );
stdlib_complex64_reim( z, &zre, &zim );

re = wre + xre + yre + zre;
im = wim + xim + yim + zim;

return stdlib_complex64( re, im );
}

// ...

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

The macro expects the following arguments:

- **fcn**: `stdlib_complex64_t (*fcn)( stdlib_complex64_t, stdlib_complex64_t, stdlib_complex64_t, stdlib_complex64_t )` quaternary 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_cccc_c( env, info, fcn )

Invokes a quaternary function accepting and returning single-precision complex floating-point numbers.

```c
#include "stdlib/complex/float32/ctor.h"
#include "stdlib/complex/float32/reim.h"
#include <node_api.h>

// ...

static stdlib_complex64_t add( const stdlib_complex64_t w, const stdlib_complex64_t x, const stdlib_complex64_t y, const stdlib_complex64_t z ) {
float wre;
float wim;
float xre;
float xim;
float yre;
float yim;
float zre;
float zim;
float re;
float im;

stdlib_complex64_reim( w, &wre, &wim );
stdlib_complex64_reim( x, &xre, &xim );
stdlib_complex64_reim( y, &yre, &yim );
stdlib_complex64_reim( z, &zre, &zim );

re = wre + xre + yre + zre;
im = wim + xim + yim + zim;

return stdlib_complex64( re, im );
}

// ...

/**
* Receives JavaScript callback invocation data.
*
* @param env environment under which the function is invoked
* @param info callback data
* @return Node-API value
*/
napi_value addon( napi_env env, napi_callback_info info ) {
return stdlib_math_base_napi_cccc_c( env, info, add );
}

// ...
```

The function accepts the following arguments:

- **env**: `[in] napi_env` environment under which the function is invoked.
- **info**: `[in] napi_callback_info` callback data.
- **fcn**: `[in] stdlib_complex64_t (*fcn)( stdlib_complex64_t, stdlib_complex64_t, stdlib_complex64_t, stdlib_complex64_t )` quaternary function.

```c
void stdlib_math_base_napi_cccc_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t, stdlib_complex64_t, stdlib_complex64_t, stdlib_complex64_t ) );
```

#### STDLIB_MATH_BASE_NAPI_MODULE_DDDD_D( fcn )

Macro for registering a Node-API module exporting an interface for invoking a quaternary function accepting and returning double-precision floating-point numbers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define STDLIB_MATH_BASE_NAPI_QUATERNARY_H

// NOTE: keep in alphabetical order...
#include "stdlib/math/base/napi/quaternary/cccc_c.h"
#include "stdlib/math/base/napi/quaternary/dddd_d.h"
#include "stdlib/math/base/napi/quaternary/diii_d.h"
#include "stdlib/math/base/napi/quaternary/ffff_f.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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_QUATERNARY_CCCC_C_H
#define STDLIB_MATH_BASE_NAPI_QUATERNARY_CCCC_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 quaternary function accepting and returning single-precision complex floating-point numbers.
*
* @param fcn quaternary function
*
* @example
* #include "stdlib/complex/float32/ctor.h"
* #include "stdlib/complex/float32/reim.h"
*
* static stdlib_complex64_t add( const stdlib_complex64_t w, const stdlib_complex64_t x, const stdlib_complex64_t y, const stdlib_complex64_t z ) {
* float wre;
* float wim;
* float xre;
* float xim;
* float yre;
* float yim;
* float zre;
* float zim;
* float re;
* float im;
*
* stdlib_complex64_reim( w, &wre, &wim );
* stdlib_complex64_reim( x, &xre, &xim );
* stdlib_complex64_reim( y, &yre, &yim );
* stdlib_complex64_reim( z, &zre, &zim );
*
* re = wre + xre + yre + zre;
* im = wim + xim + yim + zim;
*
* return stdlib_complex64( re, im );
* }
*
* // ...
*
* // Register a Node-API module:
* STDLIB_MATH_BASE_NAPI_MODULE_CCCC_C( add );
*/
#define STDLIB_MATH_BASE_NAPI_MODULE_CCCC_C( fcn ) \
static napi_value stdlib_math_base_napi_cccc_c_wrapper( \
napi_env env, \
napi_callback_info info \
) { \
return stdlib_math_base_napi_cccc_c( env, info, fcn ); \
}; \
static napi_value stdlib_math_base_napi_cccc_c_init( \
napi_env env, \
napi_value exports \
) { \
napi_value f; \
napi_status status = napi_create_function( \
env, \
"exports", \
NAPI_AUTO_LENGTH, \
stdlib_math_base_napi_cccc_c_wrapper, \
NULL, \
&f \
); \
assert( status == napi_ok ); \
return f; \
}; \
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_cccc_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 quaternary function accepting and returning single-precision complex floating-point numbers.
*/
napi_value stdlib_math_base_napi_cccc_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t, stdlib_complex64_t, stdlib_complex64_t, stdlib_complex64_t ) );

#ifdef __cplusplus
}
#endif

#endif // !STDLIB_MATH_BASE_NAPI_QUATERNARY_CCCC_C_H
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"confs": [
{
"src": [
"./src/cccc_c.c",
"./src/dddd_d.c",
"./src/diii_d.c",
"./src/ffff_f.c",
Expand All @@ -36,6 +37,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/complex/float32/ctor",
"@stdlib/complex/float32/reim",
"@stdlib/complex/float64/ctor",
"@stdlib/complex/float64/reim"
]
Expand Down
Loading