Skip to content

Commit 3224b20

Browse files
committed
feat: add CCC_C macro
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent 1994ca1 commit 3224b20

File tree

5 files changed

+430
-0
lines changed

5 files changed

+430
-0
lines changed

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

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,103 @@ console.log( headerDir );
106106

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

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

lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.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_TERNARY_H
2121

2222
// NOTE: keep in alphabetical order...
23+
#include "stdlib/math/base/napi/ternary/ccc_c.h"
2324
#include "stdlib/math/base/napi/ternary/ddd_d.h"
2425
#include "stdlib/math/base/napi/ternary/dii_d.h"
2526
#include "stdlib/math/base/napi/ternary/fff_f.h"
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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_TERNARY_CCC_C_H
20+
#define STDLIB_MATH_BASE_NAPI_TERNARY_CCC_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 ternary function accepting and returning single-precision complex floating-point numbers.
28+
*
29+
* @param fcn ternary 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 x, const stdlib_complex64_t y, const stdlib_complex64_t z ) {
36+
* float xre;
37+
* float xim;
38+
* float yre;
39+
* float yim;
40+
* float zre;
41+
* float zim;
42+
* float re;
43+
* float im;
44+
*
45+
* stdlib_complex64_reim( x, &xre, &xim );
46+
* stdlib_complex64_reim( y, &yre, &yim );
47+
* stdlib_complex64_reim( z, &zre, &zim );
48+
*
49+
* re = xre + yre + zre;
50+
* im = xim + yim + zim;
51+
*
52+
* return stdlib_complex64( re, im );
53+
* }
54+
*
55+
* // ...
56+
*
57+
* // Register a Node-API module:
58+
* STDLIB_MATH_BASE_NAPI_MODULE_CCC_C( add );
59+
*/
60+
#define STDLIB_MATH_BASE_NAPI_MODULE_CCC_C( fcn ) \
61+
static napi_value stdlib_math_base_napi_ccc_c_wrapper( \
62+
napi_env env, \
63+
napi_callback_info info \
64+
) { \
65+
return stdlib_math_base_napi_ccc_c( env, info, fcn ); \
66+
}; \
67+
static napi_value stdlib_math_base_napi_ccc_c_init( \
68+
napi_env env, \
69+
napi_value exports \
70+
) { \
71+
napi_value fcn; \
72+
napi_status status = napi_create_function( \
73+
env, \
74+
"exports", \
75+
NAPI_AUTO_LENGTH, \
76+
stdlib_math_base_napi_ccc_c_wrapper, \
77+
NULL, \
78+
&fcn \
79+
); \
80+
assert( status == napi_ok ); \
81+
return fcn; \
82+
}; \
83+
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_ccc_c_init )
84+
85+
/*
86+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
87+
*/
88+
#ifdef __cplusplus
89+
extern "C" {
90+
#endif
91+
92+
/**
93+
* Invokes a ternary function accepting and returning single-precision complex floating-point numbers.
94+
*/
95+
napi_value stdlib_math_base_napi_ccc_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t, stdlib_complex64_t, stdlib_complex64_t ) );
96+
97+
#ifdef __cplusplus
98+
}
99+
#endif
100+
101+
#endif // !STDLIB_MATH_BASE_NAPI_TERNARY_CCC_C_H

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"confs": [
2626
{
2727
"src": [
28+
"./src/ccc_c.c",
2829
"./src/ddd_d.c",
2930
"./src/dii_d.c",
3031
"./src/fff_f.c",

0 commit comments

Comments
 (0)