Skip to content

Commit 71468a6

Browse files
feat: add ZZZZ_Z macro in math/base/napi/quaternary
PR-URL: #9944 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent c625294 commit 71468a6

File tree

5 files changed

+495
-2
lines changed

5 files changed

+495
-2
lines changed

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

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,109 @@ The function accepts the following arguments:
286286
void stdlib_math_base_napi_ffff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float, float, float ) );
287287
```
288288
289+
#### STDLIB_MATH_BASE_NAPI_MODULE_ZZZZ_Z( fcn )
290+
291+
Macro for registering a Node-API module exporting an interface for invoking a quaternary function accepting and returning double-precision complex floating-point numbers.
292+
293+
```c
294+
#include "stdlib/complex/float64/ctor.h"
295+
#include "stdlib/complex/float64/reim.h"
296+
297+
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 ) {
298+
double wre;
299+
double wim;
300+
double xre;
301+
double xim;
302+
double yre;
303+
double yim;
304+
double zre;
305+
double zim;
306+
double re;
307+
double im;
308+
309+
stdlib_complex128_reim( w, &xre, &wim );
310+
stdlib_complex128_reim( x, &yre, &xim );
311+
stdlib_complex128_reim( y, &zre, &yim );
312+
stdlib_complex128_reim( z, &zre, &zim );
313+
314+
re = wre + xre + yre + zre;
315+
im = wim + xim + yim + zim;
316+
317+
return stdlib_complex128( re, im );
318+
}
319+
320+
// ...
321+
322+
// Register a Node-API module:
323+
STDLIB_MATH_BASE_NAPI_MODULE_ZZZZ_Z( add );
324+
```
325+
326+
The macro expects the following arguments:
327+
328+
- **fcn**: `stdlib_complex128_t (*fcn)( stdlib_complex128_t, stdlib_complex128_t, stdlib_complex128_t, stdlib_complex128_t )` quaternary function.
329+
330+
When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.
331+
332+
#### stdlib_math_base_napi_zzzz_z( env, info, fcn )
333+
334+
Invokes a quaternary function accepting and returning double-precision complex floating-point numbers.
335+
336+
```c
337+
#include "stdlib/complex/float64/ctor.h"
338+
#include "stdlib/complex/float64/reim.h"
339+
#include <node_api.h>
340+
341+
// ...
342+
343+
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 ) {
344+
double wre;
345+
double wim;
346+
double xre;
347+
double xim;
348+
double yre;
349+
double yim;
350+
double zre;
351+
double zim;
352+
double re;
353+
double im;
354+
355+
stdlib_complex128_reim( w, &wre, &wim );
356+
stdlib_complex128_reim( x, &xre, &xim );
357+
stdlib_complex128_reim( y, &yre, &yim );
358+
stdlib_complex128_reim( z, &zre, &zim );
359+
360+
re = wre + xre + yre + zre;
361+
im = wim + xim + yim + zim;
362+
363+
return stdlib_complex128( re, im );
364+
}
365+
366+
// ...
367+
368+
/**
369+
* Receives JavaScript callback invocation data.
370+
*
371+
* @param env environment under which the function is invoked
372+
* @param info callback data
373+
* @return Node-API value
374+
*/
375+
napi_value addon( napi_env env, napi_callback_info info ) {
376+
return stdlib_math_base_napi_zzzz_z( env, info, add );
377+
}
378+
379+
// ...
380+
```
381+
382+
The function accepts the following arguments:
383+
384+
- **env**: `[in] napi_env` environment under which the function is invoked.
385+
- **info**: `[in] napi_callback_info` callback data.
386+
- **fcn**: `[in] stdlib_complex128_t (*fcn)( stdlib_complex128_t, stdlib_complex128_t, stdlib_complex128_t, stdlib_complex128_t )` quaternary function.
387+
388+
```c
389+
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 ) );
390+
```
391+
289392
</section>
290393

291394
<!-- /.usage -->

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
#include "stdlib/math/base/napi/quaternary/dddd_d.h"
2424
#include "stdlib/math/base/napi/quaternary/diii_d.h"
2525
#include "stdlib/math/base/napi/quaternary/ffff_f.h"
26+
#include "stdlib/math/base/napi/quaternary/zzzz_z.h"
2627

2728
#endif // !STDLIB_MATH_BASE_NAPI_QUATERNARY_H
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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_QUATERNARY_ZZZZ_Z_H
20+
#define STDLIB_MATH_BASE_NAPI_QUATERNARY_ZZZZ_Z_H
21+
22+
#include "stdlib/complex/float64/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 quaternary function accepting and returning double-precision complex floating-point numbers.
28+
*
29+
* @param fcn quaternary function
30+
*
31+
* @example
32+
* #include "stdlib/complex/float64/ctor.h"
33+
* #include "stdlib/complex/float64/reim.h"
34+
*
35+
* 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 ) {
36+
* double wre;
37+
* double wim;
38+
* double xre;
39+
* double xim;
40+
* double yre;
41+
* double yim;
42+
* double zre;
43+
* double zim;
44+
* double re;
45+
* double im;
46+
*
47+
* stdlib_complex128_reim( w, &wre, &wim );
48+
* stdlib_complex128_reim( x, &xre, &xim );
49+
* stdlib_complex128_reim( y, &yre, &yim );
50+
* stdlib_complex128_reim( z, &zre, &zim );
51+
*
52+
* re = wre + xre + yre + zre;
53+
* im = wim + xim + yim + zim;
54+
*
55+
* return stdlib_complex128( re, im );
56+
* }
57+
*
58+
* // ...
59+
*
60+
* // Register a Node-API module:
61+
* STDLIB_MATH_BASE_NAPI_MODULE_ZZZZ_Z( add );
62+
*/
63+
#define STDLIB_MATH_BASE_NAPI_MODULE_ZZZZ_Z( fcn ) \
64+
static napi_value stdlib_math_base_napi_zzzz_z_wrapper( \
65+
napi_env env, \
66+
napi_callback_info info \
67+
) { \
68+
return stdlib_math_base_napi_zzzz_z( env, info, fcn ); \
69+
}; \
70+
static napi_value stdlib_math_base_napi_zzzz_z_init( \
71+
napi_env env, \
72+
napi_value exports \
73+
) { \
74+
napi_value f; \
75+
napi_status status = napi_create_function( \
76+
env, \
77+
"exports", \
78+
NAPI_AUTO_LENGTH, \
79+
stdlib_math_base_napi_zzzz_z_wrapper, \
80+
NULL, \
81+
&f \
82+
); \
83+
assert( status == napi_ok ); \
84+
return f; \
85+
}; \
86+
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_zzzz_z_init )
87+
88+
/*
89+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
90+
*/
91+
#ifdef __cplusplus
92+
extern "C" {
93+
#endif
94+
95+
/**
96+
* Invokes a quaternary function accepting and returning double-precision complex floating-point numbers.
97+
*/
98+
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 ) );
99+
100+
#ifdef __cplusplus
101+
}
102+
#endif
103+
104+
#endif // !STDLIB_MATH_BASE_NAPI_QUATERNARY_ZZZZ_Z_H

lib/node_modules/@stdlib/math/base/napi/quaternary/manifest.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@
2727
"src": [
2828
"./src/dddd_d.c",
2929
"./src/diii_d.c",
30-
"./src/ffff_f.c"
30+
"./src/ffff_f.c",
31+
"./src/zzzz_z.c"
3132
],
3233
"include": [
3334
"./include"
3435
],
3536
"libraries": [],
3637
"libpath": [],
37-
"dependencies": []
38+
"dependencies": [
39+
"@stdlib/complex/float64/ctor",
40+
"@stdlib/complex/float64/reim"
41+
]
3842
}
3943
]
4044
}

0 commit comments

Comments
 (0)