Skip to content

Commit 3e62adf

Browse files
committed
feat: add DIII_D macro in quaternary
--- 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: 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 ---
1 parent ffc6fed commit 3e62adf

File tree

4 files changed

+198
-0
lines changed

4 files changed

+198
-0
lines changed

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
@@ -21,6 +21,7 @@
2121

2222
// NOTE: keep in alphabetical order...
2323
#include "stdlib/math/base/napi/quaternary/dddd_d.h"
24+
#include "stdlib/math/base/napi/quaternary/diii_d.h"
2425
#include "stdlib/math/base/napi/quaternary/ffff_f.h"
2526

2627
#endif // !STDLIB_MATH_BASE_NAPI_QUATERNARY_H
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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_QUATERNARY_DIII_D_H
20+
#define STDLIB_MATH_BASE_NAPI_QUATERNARY_DIII_D_H
21+
22+
#include <node_api.h>
23+
#include <assert.h>
24+
#include <stdint.h>
25+
26+
/**
27+
* Macro for registering a Node-API module exporting an interface invoking a quaternary function accepting a double-precision floating-point number and three signed 32-bit integers and returning a double-precision floating-point number.
28+
*
29+
* @param fcn quaternary function
30+
*
31+
* @example
32+
* #include <stdint.h>
33+
*
34+
* static double add( const double x, const int32_t y, const int32_t z, const int32_t w ) {
35+
* return x + y + z + w;
36+
* }
37+
*
38+
* // ...
39+
*
40+
* // Register a Node-API module:
41+
* STDLIB_MATH_BASE_NAPI_MODULE_DIII_D( add );
42+
*/
43+
#define STDLIB_MATH_BASE_NAPI_MODULE_DIII_D( fcn ) \
44+
static napi_value stdlib_math_base_napi_diii_d_wrapper( \
45+
napi_env env, \
46+
napi_callback_info info \
47+
) { \
48+
return stdlib_math_base_napi_diii_d( env, info, fcn ); \
49+
}; \
50+
static napi_value stdlib_math_base_napi_diii_d_init( \
51+
napi_env env, \
52+
napi_value exports \
53+
) { \
54+
napi_value fcn; \
55+
napi_status status = napi_create_function( \
56+
env, \
57+
"exports", \
58+
NAPI_AUTO_LENGTH, \
59+
stdlib_math_base_napi_diii_d_wrapper, \
60+
NULL, \
61+
&fcn \
62+
); \
63+
assert( status == napi_ok ); \
64+
return fcn; \
65+
}; \
66+
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_diii_d_init )
67+
68+
/*
69+
* If C++, prevent name mangling so that the compiler emits a quaternary file having undecorated names, thus mirroring the behavior of a C compiler.
70+
*/
71+
#ifdef __cplusplus
72+
extern "C" {
73+
#endif
74+
75+
/**
76+
* Invokes a quaternary function accepting a double-precision floating-point number and three signed 32-bit integers and returning a double-precision floating-point number.
77+
*/
78+
napi_value stdlib_math_base_napi_diii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t, int32_t ) );
79+
80+
#ifdef __cplusplus
81+
}
82+
#endif
83+
84+
#endif // !STDLIB_MATH_BASE_NAPI_QUATERNARY_DIII_D_H

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
{
2727
"src": [
2828
"./src/dddd_d.c",
29+
"./src/diii_d.c",
2930
"./src/ffff_f.c"
3031
],
3132
"include": [
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
#include "stdlib/math/base/napi/quaternary/diii_d.h"
20+
#include <node_api.h>
21+
#include <assert.h>
22+
#include <stdint.h>
23+
24+
/**
25+
* Invokes a quaternary function accepting a double-precision floating-point number and three signed 32-bit integers and returning a double-precision floating-point number.
26+
*
27+
* ## Notes
28+
*
29+
* - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
30+
*
31+
* - `x`: input value.
32+
* - `y`: input value.
33+
* - `z`: input value.
34+
* - `w`: input value.
35+
*
36+
* @param env environment under which the function is invoked
37+
* @param info callback data
38+
* @param fcn quaternary function
39+
* @return function return value as a Node-API double-precision floating-point number
40+
*/
41+
napi_value stdlib_math_base_napi_diii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t, int32_t ) ) {
42+
napi_status status;
43+
44+
size_t argc = 4;
45+
napi_value argv[ 4 ];
46+
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
47+
assert( status == napi_ok );
48+
49+
if ( argc < 4 ) {
50+
status = napi_throw_error( env, NULL, "invalid invocation. Must provide four numbers." );
51+
assert( status == napi_ok );
52+
return NULL;
53+
}
54+
55+
napi_valuetype vtype0;
56+
status = napi_typeof( env, argv[ 0 ], &vtype0 );
57+
assert( status == napi_ok );
58+
if ( vtype0 != napi_number ) {
59+
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
60+
assert( status == napi_ok );
61+
return NULL;
62+
}
63+
64+
napi_valuetype vtype1;
65+
status = napi_typeof( env, argv[ 1 ], &vtype1 );
66+
assert( status == napi_ok );
67+
if ( vtype1 != napi_number ) {
68+
status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
69+
assert( status == napi_ok );
70+
return NULL;
71+
}
72+
73+
napi_valuetype vtype2;
74+
status = napi_typeof( env, argv[ 2 ], &vtype2 );
75+
assert( status == napi_ok );
76+
if ( vtype2 != napi_number ) {
77+
status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." );
78+
assert( status == napi_ok );
79+
return NULL;
80+
}
81+
82+
napi_valuetype vtype3;
83+
status = napi_typeof( env, argv[ 3 ], &vtype3 );
84+
assert( status == napi_ok );
85+
if ( vtype3 != napi_number ) {
86+
status = napi_throw_type_error( env, NULL, "invalid argument. Fourth argument must be a number." );
87+
assert( status == napi_ok );
88+
return NULL;
89+
}
90+
91+
double x;
92+
status = napi_get_value_double( env, argv[ 0 ], &x );
93+
assert( status == napi_ok );
94+
95+
int32_t y;
96+
status = napi_get_value_int32( env, argv[ 1 ], &y );
97+
assert( status == napi_ok );
98+
99+
int32_t z;
100+
status = napi_get_value_int32( env, argv[ 2 ], &z );
101+
assert( status == napi_ok );
102+
103+
int32_t w;
104+
status = napi_get_value_int32( env, argv[ 3 ], &w );
105+
assert( status == napi_ok );
106+
107+
napi_value v;
108+
status = napi_create_double( env, fcn( x, y, z, w ), &v );
109+
assert( status == napi_ok );
110+
111+
return v;
112+
}

0 commit comments

Comments
 (0)