@stdlib/math-base-napi-ternary 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -2
- package/include/stdlib/math/base/napi/ternary.h +47 -0
- package/package.json +5 -21
- package/src/main.c +76 -0
- package/include.gypi +0 -53
package/README.md
CHANGED
|
@@ -205,6 +205,46 @@ The function accepts the following arguments:
|
|
|
205
205
|
void stdlib_math_base_napi_fff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float, float ) );
|
|
206
206
|
```
|
|
207
207
|
|
|
208
|
+
#### stdlib_math_base_napi_dii_d( env, info, fcn )
|
|
209
|
+
|
|
210
|
+
Invokes a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number.
|
|
211
|
+
|
|
212
|
+
```c
|
|
213
|
+
#include <node_api.h>
|
|
214
|
+
#include <stdint.h>
|
|
215
|
+
|
|
216
|
+
// ...
|
|
217
|
+
|
|
218
|
+
static double fcn( const double x, const int32_t y, const int32_t z ) {
|
|
219
|
+
// ...
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// ...
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Receives JavaScript callback invocation data.
|
|
226
|
+
*
|
|
227
|
+
* @param env environment under which the function is invoked
|
|
228
|
+
* @param info callback data
|
|
229
|
+
* @return Node-API value
|
|
230
|
+
*/
|
|
231
|
+
napi_value addon( napi_env env, napi_callback_info info ) {
|
|
232
|
+
return stdlib_math_base_napi_dii_d( env, info, fcn );
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// ...
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
The function accepts the following arguments:
|
|
239
|
+
|
|
240
|
+
- **env**: `[in] napi_env` environment under which the function is invoked.
|
|
241
|
+
- **info**: `[in] napi_callback_info` callback data.
|
|
242
|
+
- **fcn**: `[in] double (*fcn)( double, int32_t, int32_t )` ternary function.
|
|
243
|
+
|
|
244
|
+
```c
|
|
245
|
+
void stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) );
|
|
246
|
+
```
|
|
247
|
+
|
|
208
248
|
#### STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( fcn )
|
|
209
249
|
|
|
210
250
|
Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting and returning double-precision floating-point numbers.
|
|
@@ -247,6 +287,29 @@ The macro expects the following arguments:
|
|
|
247
287
|
|
|
248
288
|
When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.
|
|
249
289
|
|
|
290
|
+
#### STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn )
|
|
291
|
+
|
|
292
|
+
Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number.
|
|
293
|
+
|
|
294
|
+
```c
|
|
295
|
+
#include <stdint.h>
|
|
296
|
+
|
|
297
|
+
static double fcn( const double x, const int32_t y, const int32_t z ) {
|
|
298
|
+
// ...
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// ...
|
|
302
|
+
|
|
303
|
+
// Register a Node-API module:
|
|
304
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn );
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
The macro expects the following arguments:
|
|
308
|
+
|
|
309
|
+
- **fcn**: `double (*fcn)( double, int32_t, int32_t )` ternary function.
|
|
310
|
+
|
|
311
|
+
When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.
|
|
312
|
+
|
|
250
313
|
</section>
|
|
251
314
|
|
|
252
315
|
<!-- /.usage -->
|
|
@@ -334,8 +397,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
334
397
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-napi-ternary.svg
|
|
335
398
|
[npm-url]: https://npmjs.org/package/@stdlib/math-base-napi-ternary
|
|
336
399
|
|
|
337
|
-
[test-image]: https://github.com/stdlib-js/math-base-napi-ternary/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
338
|
-
[test-url]: https://github.com/stdlib-js/math-base-napi-ternary/actions/workflows/test.yml?query=branch:v0.
|
|
400
|
+
[test-image]: https://github.com/stdlib-js/math-base-napi-ternary/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
401
|
+
[test-url]: https://github.com/stdlib-js/math-base-napi-ternary/actions/workflows/test.yml?query=branch:v0.3.0
|
|
339
402
|
|
|
340
403
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-napi-ternary/main.svg
|
|
341
404
|
[coverage-url]: https://codecov.io/github/stdlib-js/math-base-napi-ternary?branch=main
|
|
@@ -102,6 +102,48 @@
|
|
|
102
102
|
}; \
|
|
103
103
|
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_fff_f_init )
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number.
|
|
107
|
+
*
|
|
108
|
+
* @param fcn ternary function
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* #include <stdint.h>
|
|
112
|
+
*
|
|
113
|
+
* static double fcn( const double x, const int_32 y, const int_32 z ) {
|
|
114
|
+
* // ...
|
|
115
|
+
* }
|
|
116
|
+
*
|
|
117
|
+
* // ...
|
|
118
|
+
*
|
|
119
|
+
* // Register a Node-API module:
|
|
120
|
+
* STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn );
|
|
121
|
+
*/
|
|
122
|
+
#define STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn ) \
|
|
123
|
+
static napi_value stdlib_math_base_napi_dii_d_wrapper( \
|
|
124
|
+
napi_env env, \
|
|
125
|
+
napi_callback_info info \
|
|
126
|
+
) { \
|
|
127
|
+
return stdlib_math_base_napi_dii_d( env, info, fcn ); \
|
|
128
|
+
}; \
|
|
129
|
+
static napi_value stdlib_math_base_napi_dii_d_init( \
|
|
130
|
+
napi_env env, \
|
|
131
|
+
napi_value exports \
|
|
132
|
+
) { \
|
|
133
|
+
napi_value fcn; \
|
|
134
|
+
napi_status status = napi_create_function( \
|
|
135
|
+
env, \
|
|
136
|
+
"exports", \
|
|
137
|
+
NAPI_AUTO_LENGTH, \
|
|
138
|
+
stdlib_math_base_napi_dii_d_wrapper, \
|
|
139
|
+
NULL, \
|
|
140
|
+
&fcn \
|
|
141
|
+
); \
|
|
142
|
+
assert( status == napi_ok ); \
|
|
143
|
+
return fcn; \
|
|
144
|
+
}; \
|
|
145
|
+
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_dii_d_init )
|
|
146
|
+
|
|
105
147
|
/*
|
|
106
148
|
* If C++, prevent name mangling so that the compiler emits a ternary file having undecorated names, thus mirroring the behavior of a C compiler.
|
|
107
149
|
*/
|
|
@@ -119,6 +161,11 @@ napi_value stdlib_math_base_napi_ddd_d( napi_env env, napi_callback_info info, d
|
|
|
119
161
|
*/
|
|
120
162
|
napi_value stdlib_math_base_napi_fff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float, float ) );
|
|
121
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Invokes a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number.
|
|
166
|
+
*/
|
|
167
|
+
napi_value stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) );
|
|
168
|
+
|
|
122
169
|
#ifdef __cplusplus
|
|
123
170
|
}
|
|
124
171
|
#endif
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/math-base-napi-ternary",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "C APIs for registering a Node-API module exporting an interface for invoking a ternary numerical function.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -17,21 +17,14 @@
|
|
|
17
17
|
"browser": "./lib/browser.js",
|
|
18
18
|
"gypfile": false,
|
|
19
19
|
"directories": {
|
|
20
|
-
"benchmark": "./benchmark",
|
|
21
20
|
"doc": "./docs",
|
|
22
|
-
"example": "./examples",
|
|
23
21
|
"include": "./include",
|
|
24
22
|
"lib": "./lib",
|
|
25
23
|
"src": "./src",
|
|
26
|
-
"
|
|
24
|
+
"dist": "./dist"
|
|
27
25
|
},
|
|
28
26
|
"types": "./docs/types",
|
|
29
|
-
"scripts": {
|
|
30
|
-
"test": "make test",
|
|
31
|
-
"test-cov": "make test-cov",
|
|
32
|
-
"examples": "make examples",
|
|
33
|
-
"benchmark": "make benchmark"
|
|
34
|
-
},
|
|
27
|
+
"scripts": {},
|
|
35
28
|
"homepage": "https://stdlib.io",
|
|
36
29
|
"repository": {
|
|
37
30
|
"type": "git",
|
|
@@ -41,18 +34,9 @@
|
|
|
41
34
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
42
35
|
},
|
|
43
36
|
"dependencies": {
|
|
44
|
-
"@stdlib/utils-library-manifest": "^0.2.
|
|
45
|
-
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"@stdlib/assert-is-browser": "^0.1.1",
|
|
48
|
-
"@stdlib/math-base-assert-is-nan": "^0.1.1",
|
|
49
|
-
"@stdlib/utils-try-require": "^0.2.0",
|
|
50
|
-
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
51
|
-
"istanbul": "^0.4.1",
|
|
52
|
-
"tap-min": "git+https://github.com/Planeshifter/tap-min.git",
|
|
53
|
-
"@stdlib/bench-harness": "^0.1.2",
|
|
54
|
-
"@stdlib/bench": "^0.3.1"
|
|
37
|
+
"@stdlib/utils-library-manifest": "^0.2.1"
|
|
55
38
|
},
|
|
39
|
+
"devDependencies": {},
|
|
56
40
|
"engines": {
|
|
57
41
|
"node": ">=0.10.0",
|
|
58
42
|
"npm": ">2.7.0"
|
package/src/main.c
CHANGED
|
@@ -172,3 +172,79 @@ napi_value stdlib_math_base_napi_fff_f( napi_env env, napi_callback_info info, f
|
|
|
172
172
|
|
|
173
173
|
return v;
|
|
174
174
|
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Invokes a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number.
|
|
178
|
+
*
|
|
179
|
+
* ## Notes
|
|
180
|
+
*
|
|
181
|
+
* - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
|
|
182
|
+
*
|
|
183
|
+
* - `x`: input value.
|
|
184
|
+
* - `y`: input value.
|
|
185
|
+
* - `z`: input value.
|
|
186
|
+
*
|
|
187
|
+
* @param env environment under which the function is invoked
|
|
188
|
+
* @param info callback data
|
|
189
|
+
* @param fcn ternary function
|
|
190
|
+
* @return function return value as a Node-API double-precision floating-point number
|
|
191
|
+
*/
|
|
192
|
+
napi_value stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) ) {
|
|
193
|
+
napi_status status;
|
|
194
|
+
|
|
195
|
+
size_t argc = 3;
|
|
196
|
+
napi_value argv[ 3 ];
|
|
197
|
+
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
|
|
198
|
+
assert( status == napi_ok );
|
|
199
|
+
|
|
200
|
+
if ( argc < 3 ) {
|
|
201
|
+
status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." );
|
|
202
|
+
assert( status == napi_ok );
|
|
203
|
+
return NULL;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
napi_valuetype vtype0;
|
|
207
|
+
status = napi_typeof( env, argv[ 0 ], &vtype0 );
|
|
208
|
+
assert( status == napi_ok );
|
|
209
|
+
if ( vtype0 != napi_number ) {
|
|
210
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
|
|
211
|
+
assert( status == napi_ok );
|
|
212
|
+
return NULL;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
napi_valuetype vtype1;
|
|
216
|
+
status = napi_typeof( env, argv[ 1 ], &vtype1 );
|
|
217
|
+
assert( status == napi_ok );
|
|
218
|
+
if ( vtype1 != napi_number ) {
|
|
219
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
|
|
220
|
+
assert( status == napi_ok );
|
|
221
|
+
return NULL;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
napi_valuetype vtype2;
|
|
225
|
+
status = napi_typeof( env, argv[ 2 ], &vtype2 );
|
|
226
|
+
assert( status == napi_ok );
|
|
227
|
+
if ( vtype2 != napi_number ) {
|
|
228
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." );
|
|
229
|
+
assert( status == napi_ok );
|
|
230
|
+
return NULL;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
double x;
|
|
234
|
+
status = napi_get_value_double( env, argv[ 0 ], &x );
|
|
235
|
+
assert( status == napi_ok );
|
|
236
|
+
|
|
237
|
+
int32_t y;
|
|
238
|
+
status = napi_get_value_int32( env, argv[ 1 ], &y );
|
|
239
|
+
assert( status == napi_ok );
|
|
240
|
+
|
|
241
|
+
int32_t z;
|
|
242
|
+
status = napi_get_value_int32( env, argv[ 2 ], &z );
|
|
243
|
+
assert( status == napi_ok );
|
|
244
|
+
|
|
245
|
+
napi_value v;
|
|
246
|
+
status = napi_create_double( env, fcn( x, y, z ), &v );
|
|
247
|
+
assert( status == napi_ok );
|
|
248
|
+
|
|
249
|
+
return v;
|
|
250
|
+
}
|
package/include.gypi
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# @license Apache-2.0
|
|
2
|
-
#
|
|
3
|
-
# Copyright (c) 2020 The Stdlib Authors.
|
|
4
|
-
#
|
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
# you may not use this file except in compliance with the License.
|
|
7
|
-
# You may obtain a copy of the License at
|
|
8
|
-
#
|
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
#
|
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
# See the License for the specific language governing permissions and
|
|
15
|
-
# limitations under the License.
|
|
16
|
-
|
|
17
|
-
# A GYP include file for building a Node.js native add-on.
|
|
18
|
-
#
|
|
19
|
-
# Main documentation:
|
|
20
|
-
#
|
|
21
|
-
# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md
|
|
22
|
-
# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md
|
|
23
|
-
{
|
|
24
|
-
# Define variables to be used throughout the configuration for all targets:
|
|
25
|
-
'variables': {
|
|
26
|
-
# Source directory:
|
|
27
|
-
'src_dir': './src',
|
|
28
|
-
|
|
29
|
-
# Include directories:
|
|
30
|
-
'include_dirs': [
|
|
31
|
-
'<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).include; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
|
|
32
|
-
],
|
|
33
|
-
|
|
34
|
-
# Add-on destination directory:
|
|
35
|
-
'addon_output_dir': './src',
|
|
36
|
-
|
|
37
|
-
# Source files:
|
|
38
|
-
'src_files': [
|
|
39
|
-
'<(src_dir)/addon.c',
|
|
40
|
-
'<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
|
|
41
|
-
],
|
|
42
|
-
|
|
43
|
-
# Library dependencies:
|
|
44
|
-
'libraries': [
|
|
45
|
-
'<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libraries; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
|
|
46
|
-
],
|
|
47
|
-
|
|
48
|
-
# Library directories:
|
|
49
|
-
'library_dirs': [
|
|
50
|
-
'<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libpath; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
|
|
51
|
-
],
|
|
52
|
-
}, # end variables
|
|
53
|
-
}
|