Skip to content

Commit 4fbdfd9

Browse files
committed
feat: add III_D macro in ternary
--- 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: na - 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: na - 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 ---
1 parent 76a5486 commit 4fbdfd9

File tree

2 files changed

+123
-0
lines changed
  • lib/node_modules/@stdlib/math/base/napi/ternary

2 files changed

+123
-0
lines changed

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,48 @@
186186
}; \
187187
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_iid_d_init )
188188

189+
/**
190+
* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting three signed 32-bit integers and returning a double-precision floating-point number.
191+
*
192+
* @param fcn ternary function
193+
*
194+
* @example
195+
* #include <stdint.h>
196+
*
197+
* static double fcn( const int32_t x, const int32_t y, const int32_t z ) {
198+
* // ...
199+
* }
200+
*
201+
* // ...
202+
*
203+
* // Register a Node-API module:
204+
* STDLIB_MATH_BASE_NAPI_MODULE_III_D( fcn );
205+
*/
206+
#define STDLIB_MATH_BASE_NAPI_MODULE_III_D( fcn ) \
207+
static napi_value stdlib_math_base_napi_iii_d_wrapper( \
208+
napi_env env, \
209+
napi_callback_info info \
210+
) { \
211+
return stdlib_math_base_napi_iii_d( env, info, fcn ); \
212+
}; \
213+
static napi_value stdlib_math_base_napi_iii_d_init( \
214+
napi_env env, \
215+
napi_value exports \
216+
) { \
217+
napi_value fcn; \
218+
napi_status status = napi_create_function( \
219+
env, \
220+
"exports", \
221+
NAPI_AUTO_LENGTH, \
222+
stdlib_math_base_napi_iii_d_wrapper, \
223+
NULL, \
224+
&fcn \
225+
); \
226+
assert( status == napi_ok ); \
227+
return fcn; \
228+
}; \
229+
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_iii_d_init )
230+
189231
/*
190232
* If C++, prevent name mangling so that the compiler emits a ternary file having undecorated names, thus mirroring the behavior of a C compiler.
191233
*/
@@ -213,6 +255,11 @@ napi_value stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, d
213255
*/
214256
napi_value stdlib_math_base_napi_iid_d( napi_env env, napi_callback_info info, double (*fcn)( int32_t, int32_t, double ) );
215257

258+
/**
259+
* Invokes a ternary function accepting three signed 32-bit integers and returning a double-precision floating-point number.
260+
*/
261+
napi_value stdlib_math_base_napi_iii_d( napi_env env, napi_callback_info info, double (*fcn)( int32_t, int32_t, int32_t ) );
262+
216263
#ifdef __cplusplus
217264
}
218265
#endif

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
@@ -324,3 +324,79 @@ napi_value stdlib_math_base_napi_iid_d( napi_env env, napi_callback_info info, d
324324

325325
return v;
326326
}
327+
328+
/**
329+
* Invokes a ternary function accepting three signed 32-bit integers and returning a double-precision floating-point number.
330+
*
331+
* ## Notes
332+
*
333+
* - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
334+
*
335+
* - `x`: input value.
336+
* - `y`: input value.
337+
* - `z`: input value.
338+
*
339+
* @param env environment under which the function is invoked
340+
* @param info callback data
341+
* @param fcn ternary function
342+
* @return function return value as a Node-API double-precision floating-point number
343+
*/
344+
napi_value stdlib_math_base_napi_iii_d( napi_env env, napi_callback_info info, double (*fcn)( int32_t, int32_t, int32_t ) ) {
345+
napi_status status;
346+
347+
size_t argc = 3;
348+
napi_value argv[ 3 ];
349+
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
350+
assert( status == napi_ok );
351+
352+
if ( argc < 3 ) {
353+
status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." );
354+
assert( status == napi_ok );
355+
return NULL;
356+
}
357+
358+
napi_valuetype vtype0;
359+
status = napi_typeof( env, argv[ 0 ], &vtype0 );
360+
assert( status == napi_ok );
361+
if ( vtype0 != napi_number ) {
362+
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
363+
assert( status == napi_ok );
364+
return NULL;
365+
}
366+
367+
napi_valuetype vtype1;
368+
status = napi_typeof( env, argv[ 1 ], &vtype1 );
369+
assert( status == napi_ok );
370+
if ( vtype1 != napi_number ) {
371+
status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
372+
assert( status == napi_ok );
373+
return NULL;
374+
}
375+
376+
napi_valuetype vtype2;
377+
status = napi_typeof( env, argv[ 2 ], &vtype2 );
378+
assert( status == napi_ok );
379+
if ( vtype2 != napi_number ) {
380+
status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." );
381+
assert( status == napi_ok );
382+
return NULL;
383+
}
384+
385+
int32_t x;
386+
status = napi_get_value_int32( env, argv[ 0 ], &x );
387+
assert( status == napi_ok );
388+
389+
int32_t y;
390+
status = napi_get_value_int32( env, argv[ 1 ], &y );
391+
assert( status == napi_ok );
392+
393+
int32_t z;
394+
status = napi_get_value_int32( env, argv[ 2 ], &z );
395+
assert( status == napi_ok );
396+
397+
napi_value v;
398+
status = napi_create_double( env, fcn( x, y, z ), &v );
399+
assert( status == napi_ok );
400+
401+
return v;
402+
}

0 commit comments

Comments
 (0)