Skip to content
Open
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 @@ -286,6 +286,109 @@ The function accepts the following arguments:
void stdlib_math_base_napi_ffff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float, float, float ) );
```

#### STDLIB_MATH_BASE_NAPI_MODULE_ZZZZ_Z( fcn )

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

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

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

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

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

return stdlib_complex128( re, im );
}

// ...

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

The macro expects the following arguments:

- **fcn**: `stdlib_complex128_t (*fcn)( stdlib_complex128_t, stdlib_complex128_t, stdlib_complex128_t, stdlib_complex128_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_zzzz_z( env, info, fcn )

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

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

// ...

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

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

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

return stdlib_complex128( 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_zzzz_z( 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_complex128_t (*fcn)( stdlib_complex128_t, stdlib_complex128_t, stdlib_complex128_t, stdlib_complex128_t )` quaternary function.

```c
void stdlib_math_base_napi_zzzz_z( napi_env env, napi_callback_info info, stdlib_complex128_t (*fcn)( stdlib_complex128_t, stdlib_complex128_t, stdlib_complex128_t, stdlib_complex128_t ) );
```

</section>

<!-- /.usage -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
#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"
#include "stdlib/math/base/napi/quaternary/zzzz_z.h"

#endif // !STDLIB_MATH_BASE_NAPI_QUATERNARY_H
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_ZZZZ_Z_H
#define STDLIB_MATH_BASE_NAPI_QUATERNARY_ZZZZ_Z_H

#include "stdlib/complex/float64/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 double-precision complex floating-point numbers.
*
* @param fcn quaternary function
*
* @example
* #include "stdlib/complex/float64/ctor.h"
* #include "stdlib/complex/float64/reim.h"
*
* static stdlib_complex128_t add( const stdlib_complex128_t w, const stdlib_complex128_t x, const stdlib_complex128_t y, const stdlib_complex128_t z ) {
* double wre;
* double wim;
* double xre;
* double xim;
* double yre;
* double yim;
* double zre;
* double zim;
* double re;
* double im;
*
* stdlib_complex128_reim( w, &wre, &wim );
* stdlib_complex128_reim( x, &xre, &xim );
* stdlib_complex128_reim( y, &yre, &yim );
* stdlib_complex128_reim( z, &zre, &zim );
*
* re = wre + xre + yre + zre;
* im = wim + xim + yim + zim;
*
* return stdlib_complex128( re, im );
* }
*
* // ...
*
* // Register a Node-API module:
* STDLIB_MATH_BASE_NAPI_MODULE_ZZZZ_Z( add );
*/
#define STDLIB_MATH_BASE_NAPI_MODULE_ZZZZ_Z( fcn ) \
static napi_value stdlib_math_base_napi_zzzz_z_wrapper( \
napi_env env, \
napi_callback_info info \
) { \
return stdlib_math_base_napi_zzzz_z( env, info, fcn ); \
}; \
static napi_value stdlib_math_base_napi_zzzz_z_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_zzzz_z_wrapper, \
NULL, \
&f \
); \
assert( status == napi_ok ); \
return f; \
}; \
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_zzzz_z_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 double-precision complex floating-point numbers.
*/
napi_value stdlib_math_base_napi_zzzz_z( napi_env env, napi_callback_info info, stdlib_complex128_t (*fcn)( stdlib_complex128_t, stdlib_complex128_t, stdlib_complex128_t, stdlib_complex128_t ) );

#ifdef __cplusplus
}
#endif

#endif // !STDLIB_MATH_BASE_NAPI_QUATERNARY_ZZZZ_Z_H
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@
"src": [
"./src/dddd_d.c",
"./src/diii_d.c",
"./src/ffff_f.c"
"./src/ffff_f.c",
"./src/zzzz_z.c"
],
"include": [
"./include"
],
"libraries": [],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/complex/float64/ctor",
"@stdlib/complex/float64/reim"
]
}
]
}
Loading