Skip to content

Commit e196c42

Browse files
feat: add CCCC_C macro in math/base/napi/quaternary
PR-URL: #11105 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 647e0b1 commit e196c42

File tree

5 files changed

+492
-0
lines changed

5 files changed

+492
-0
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
@@ -106,6 +106,109 @@ console.log( headerDir );
106106

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

109+
#### STDLIB_MATH_BASE_NAPI_MODULE_CCCC_C( fcn )
110+
111+
Macro for registering a Node-API module exporting an interface for invoking a quaternary function accepting and returning single-precision complex floating-point numbers.
112+
113+
```c
114+
#include "stdlib/complex/float32/ctor.h"
115+
#include "stdlib/complex/float32/reim.h"
116+
117+
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 ) {
118+
float wre;
119+
float wim;
120+
float xre;
121+
float xim;
122+
float yre;
123+
float yim;
124+
float zre;
125+
float zim;
126+
float re;
127+
float im;
128+
129+
stdlib_complex64_reim( w, &wre, &wim );
130+
stdlib_complex64_reim( x, &xre, &xim );
131+
stdlib_complex64_reim( y, &yre, &yim );
132+
stdlib_complex64_reim( z, &zre, &zim );
133+
134+
re = wre + xre + yre + zre;
135+
im = wim + xim + yim + zim;
136+
137+
return stdlib_complex64( re, im );
138+
}
139+
140+
// ...
141+
142+
// Register a Node-API module:
143+
STDLIB_MATH_BASE_NAPI_MODULE_CCCC_C( add );
144+
```
145+
146+
The macro expects the following arguments:
147+
148+
- **fcn**: `stdlib_complex64_t (*fcn)( stdlib_complex64_t, stdlib_complex64_t, stdlib_complex64_t, stdlib_complex64_t )` quaternary function.
149+
150+
When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.
151+
152+
#### stdlib_math_base_napi_cccc_c( env, info, fcn )
153+
154+
Invokes a quaternary function accepting and returning single-precision complex floating-point numbers.
155+
156+
```c
157+
#include "stdlib/complex/float32/ctor.h"
158+
#include "stdlib/complex/float32/reim.h"
159+
#include <node_api.h>
160+
161+
// ...
162+
163+
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 ) {
164+
float wre;
165+
float wim;
166+
float xre;
167+
float xim;
168+
float yre;
169+
float yim;
170+
float zre;
171+
float zim;
172+
float re;
173+
float im;
174+
175+
stdlib_complex64_reim( w, &wre, &wim );
176+
stdlib_complex64_reim( x, &xre, &xim );
177+
stdlib_complex64_reim( y, &yre, &yim );
178+
stdlib_complex64_reim( z, &zre, &zim );
179+
180+
re = wre + xre + yre + zre;
181+
im = wim + xim + yim + zim;
182+
183+
return stdlib_complex64( re, im );
184+
}
185+
186+
// ...
187+
188+
/**
189+
* Receives JavaScript callback invocation data.
190+
*
191+
* @param env environment under which the function is invoked
192+
* @param info callback data
193+
* @return Node-API value
194+
*/
195+
napi_value addon( napi_env env, napi_callback_info info ) {
196+
return stdlib_math_base_napi_cccc_c( env, info, add );
197+
}
198+
199+
// ...
200+
```
201+
202+
The function accepts the following arguments:
203+
204+
- **env**: `[in] napi_env` environment under which the function is invoked.
205+
- **info**: `[in] napi_callback_info` callback data.
206+
- **fcn**: `[in] stdlib_complex64_t (*fcn)( stdlib_complex64_t, stdlib_complex64_t, stdlib_complex64_t, stdlib_complex64_t )` quaternary function.
207+
208+
```c
209+
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 ) );
210+
```
211+
109212
#### STDLIB_MATH_BASE_NAPI_MODULE_DDDD_D( fcn )
110213
111214
Macro for registering a Node-API module exporting an interface for invoking a quaternary function accepting and returning double-precision floating-point numbers.

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
@@ -20,6 +20,7 @@
2020
#define STDLIB_MATH_BASE_NAPI_QUATERNARY_H
2121

2222
// NOTE: keep in alphabetical order...
23+
#include "stdlib/math/base/napi/quaternary/cccc_c.h"
2324
#include "stdlib/math/base/napi/quaternary/dddd_d.h"
2425
#include "stdlib/math/base/napi/quaternary/diii_d.h"
2526
#include "stdlib/math/base/napi/quaternary/ffff_f.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_CCCC_C_H
20+
#define STDLIB_MATH_BASE_NAPI_QUATERNARY_CCCC_C_H
21+
22+
#include "stdlib/complex/float32/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 single-precision complex floating-point numbers.
28+
*
29+
* @param fcn quaternary function
30+
*
31+
* @example
32+
* #include "stdlib/complex/float32/ctor.h"
33+
* #include "stdlib/complex/float32/reim.h"
34+
*
35+
* 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 ) {
36+
* float wre;
37+
* float wim;
38+
* float xre;
39+
* float xim;
40+
* float yre;
41+
* float yim;
42+
* float zre;
43+
* float zim;
44+
* float re;
45+
* float im;
46+
*
47+
* stdlib_complex64_reim( w, &wre, &wim );
48+
* stdlib_complex64_reim( x, &xre, &xim );
49+
* stdlib_complex64_reim( y, &yre, &yim );
50+
* stdlib_complex64_reim( z, &zre, &zim );
51+
*
52+
* re = wre + xre + yre + zre;
53+
* im = wim + xim + yim + zim;
54+
*
55+
* return stdlib_complex64( re, im );
56+
* }
57+
*
58+
* // ...
59+
*
60+
* // Register a Node-API module:
61+
* STDLIB_MATH_BASE_NAPI_MODULE_CCCC_C( add );
62+
*/
63+
#define STDLIB_MATH_BASE_NAPI_MODULE_CCCC_C( fcn ) \
64+
static napi_value stdlib_math_base_napi_cccc_c_wrapper( \
65+
napi_env env, \
66+
napi_callback_info info \
67+
) { \
68+
return stdlib_math_base_napi_cccc_c( env, info, fcn ); \
69+
}; \
70+
static napi_value stdlib_math_base_napi_cccc_c_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_cccc_c_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_cccc_c_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 single-precision complex floating-point numbers.
97+
*/
98+
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 ) );
99+
100+
#ifdef __cplusplus
101+
}
102+
#endif
103+
104+
#endif // !STDLIB_MATH_BASE_NAPI_QUATERNARY_CCCC_C_H

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"confs": [
2626
{
2727
"src": [
28+
"./src/cccc_c.c",
2829
"./src/dddd_d.c",
2930
"./src/diii_d.c",
3031
"./src/ffff_f.c",
@@ -36,6 +37,8 @@
3637
"libraries": [],
3738
"libpath": [],
3839
"dependencies": [
40+
"@stdlib/complex/float32/ctor",
41+
"@stdlib/complex/float32/reim",
3942
"@stdlib/complex/float64/ctor",
4043
"@stdlib/complex/float64/reim"
4144
]

0 commit comments

Comments
 (0)