Skip to content

Commit cc8ee1d

Browse files
feat: added did_d function
--- 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: na - 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 f48cd36 commit cc8ee1d

File tree

3 files changed

+158
-0
lines changed

3 files changed

+158
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,46 @@ The function accepts the following arguments:
222222
void stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) );
223223
```
224224

225+
#### stdlib_math_base_napi_did_d( env, info, fcn )
226+
227+
Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number.
228+
229+
```c
230+
#include <node_api.h>
231+
#include <stdint.h>
232+
233+
// ...
234+
235+
static double fcn( const double x, const int32_t y, const double z ) {
236+
// ...
237+
}
238+
239+
// ...
240+
241+
/**
242+
* Receives JavaScript callback invocation data.
243+
*
244+
* @param env environment under which the function is invoked
245+
* @param info callback data
246+
* @return Node-API value
247+
*/
248+
napi_value addon( napi_env env, napi_callback_info info ) {
249+
return stdlib_math_base_napi_did_d( env, info, fcn );
250+
}
251+
252+
// ...
253+
```
254+
255+
The function accepts the following arguments:
256+
257+
- **env**: `[in] napi_env` environment under which the function is invoked.
258+
- **info**: `[in] napi_callback_info` callback data.
259+
- **fcn**: `[in] double (*fcn)( double, int32_t, double )` ternary function.
260+
261+
```c
262+
void stdlib_math_base_napi_did_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, double ) );
263+
```
264+
225265
#### stdlib_math_base_napi_iid_d( env, info, fcn )
226266

227267
Invokes a ternary function accepting two signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number.

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,48 @@
144144
}; \
145145
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_dii_d_init )
146146

147+
/**
148+
* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number.
149+
*
150+
* @param fcn ternary function
151+
*
152+
* @example
153+
* #include <stdint.h>
154+
*
155+
* static double fcn( const double x, const int_32 y, const double z ) {
156+
* // ...
157+
* }
158+
*
159+
* // ...
160+
*
161+
* // Register a Node-API module:
162+
* STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn );
163+
*/
164+
#define STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn ) \
165+
static napi_value stdlib_math_base_napi_did_d_wrapper( \
166+
napi_env env, \
167+
napi_callback_info info \
168+
) { \
169+
return stdlib_math_base_napi_did_d( env, info, fcn ); \
170+
}; \
171+
static napi_value stdlib_math_base_napi_did_d_init( \
172+
napi_env env, \
173+
napi_value exports \
174+
) { \
175+
napi_value fcn; \
176+
napi_status status = napi_create_function( \
177+
env, \
178+
"exports", \
179+
NAPI_AUTO_LENGTH, \
180+
stdlib_math_base_napi_did_d_wrapper, \
181+
NULL, \
182+
&fcn \
183+
); \
184+
assert( status == napi_ok ); \
185+
return fcn; \
186+
}; \
187+
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_did_d_init )
188+
147189
/**
148190
* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting two signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number.
149191
*

lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,82 @@ napi_value stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, d
249249
return v;
250250
}
251251

252+
/**
253+
* Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number.
254+
*
255+
* ## Notes
256+
*
257+
* - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
258+
*
259+
* - `x`: input value.
260+
* - `y`: input value.
261+
* - `z`: input value.
262+
*
263+
* @param env environment under which the function is invoked
264+
* @param info callback data
265+
* @param fcn ternary function
266+
* @return function return value as a Node-API double-precision floating-point number
267+
*/
268+
napi_value stdlib_math_base_napi_did_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, double ) ) {
269+
napi_status status;
270+
271+
size_t argc = 3;
272+
napi_value argv[ 3 ];
273+
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
274+
assert( status == napi_ok );
275+
276+
if ( argc < 3 ) {
277+
status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." );
278+
assert( status == napi_ok );
279+
return NULL;
280+
}
281+
282+
napi_valuetype vtype0;
283+
status = napi_typeof( env, argv[ 0 ], &vtype0 );
284+
assert( status == napi_ok );
285+
if ( vtype0 != napi_number ) {
286+
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
287+
assert( status == napi_ok );
288+
return NULL;
289+
}
290+
291+
napi_valuetype vtype1;
292+
status = napi_typeof( env, argv[ 1 ], &vtype1 );
293+
assert( status == napi_ok );
294+
if ( vtype1 != napi_number ) {
295+
status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
296+
assert( status == napi_ok );
297+
return NULL;
298+
}
299+
300+
napi_valuetype vtype2;
301+
status = napi_typeof( env, argv[ 2 ], &vtype2 );
302+
assert( status == napi_ok );
303+
if ( vtype2 != napi_number ) {
304+
status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." );
305+
assert( status == napi_ok );
306+
return NULL;
307+
}
308+
309+
double x;
310+
status = napi_get_value_double( env, argv[ 0 ], &x );
311+
assert( status == napi_ok );
312+
313+
int32_t y;
314+
status = napi_get_value_int32( env, argv[ 1 ], &y );
315+
assert( status == napi_ok );
316+
317+
double z;
318+
status = napi_get_value_double( env, argv[ 2 ], &z );
319+
assert( status == napi_ok );
320+
321+
napi_value v;
322+
status = napi_create_double( env, fcn( x, y, z ), &v );
323+
assert( status == napi_ok );
324+
325+
return v;
326+
}
327+
252328
/**
253329
* Invokes a ternary function accepting two signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number.
254330
*

0 commit comments

Comments
 (0)