@stdlib/math-base-napi-unary 0.0.7 → 0.0.8
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/NOTICE +1 -1
- package/README.md +292 -13
- package/include/stdlib/math/base/napi/unary.h +208 -0
- package/manifest.json +6 -1
- package/package.json +5 -1
- package/src/main.c +387 -0
- package/binding.gyp +0 -170
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2022 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ limitations under the License.
|
|
|
20
20
|
|
|
21
21
|
# unary
|
|
22
22
|
|
|
23
|
-
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] [![dependencies][dependencies-image]][dependencies-url]
|
|
23
|
+
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
24
24
|
|
|
25
25
|
> C APIs for registering a Node-API module exporting interfaces for invoking unary numerical functions.
|
|
26
26
|
|
|
@@ -108,16 +108,6 @@ console.log( headerDir );
|
|
|
108
108
|
|
|
109
109
|
<!-- C usage documentation. -->
|
|
110
110
|
|
|
111
|
-
<section class="installation">
|
|
112
|
-
|
|
113
|
-
## Installation
|
|
114
|
-
|
|
115
|
-
```bash
|
|
116
|
-
npm install @stdlib/math-base-napi-unary
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
</section>
|
|
120
|
-
|
|
121
111
|
<section class="usage">
|
|
122
112
|
|
|
123
113
|
### Usage
|
|
@@ -204,6 +194,166 @@ The function accepts the following arguments:
|
|
|
204
194
|
void stdlib_math_base_napi_f_f( napi_env env, napi_callback_info info, float (*fcn)( float ) );
|
|
205
195
|
```
|
|
206
196
|
|
|
197
|
+
#### stdlib_math_base_napi_z_z( env, info, fcn )
|
|
198
|
+
|
|
199
|
+
Invokes a unary function accepting and returning double-precision complex floating-point numbers.
|
|
200
|
+
|
|
201
|
+
```c
|
|
202
|
+
#include "stdlib/complex/float64.h"
|
|
203
|
+
#include <node_api.h>
|
|
204
|
+
|
|
205
|
+
// ...
|
|
206
|
+
|
|
207
|
+
static stdlib_complex128_t identity( const stdlib_complex128_t x ) {
|
|
208
|
+
return x;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ...
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Receives JavaScript callback invocation data.
|
|
215
|
+
*
|
|
216
|
+
* @param env environment under which the function is invoked
|
|
217
|
+
* @param info callback data
|
|
218
|
+
* @return Node-API value
|
|
219
|
+
*/
|
|
220
|
+
napi_value addon( napi_env env, napi_callback_info info ) {
|
|
221
|
+
return stdlib_math_base_napi_z_z( env, info, identity );
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ...
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
The function accepts the following arguments:
|
|
228
|
+
|
|
229
|
+
- **env**: `[in] napi_env` environment under which the function is invoked.
|
|
230
|
+
- **info**: `[in] napi_callback_info` callback data.
|
|
231
|
+
- **fcn**: `[in] stdlib_complex128_t (*fcn)( stdlib_complex128_t )` unary function.
|
|
232
|
+
|
|
233
|
+
```c
|
|
234
|
+
void stdlib_math_base_napi_z_z( napi_env env, napi_callback_info info, stdlib_complex128_t (*fcn)( stdlib_complex128_t ) );
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
#### stdlib_math_base_napi_z_d( env, info, fcn )
|
|
238
|
+
|
|
239
|
+
Invokes a unary function accepting a double-precision complex floating-point number and returning a double-precision floating-point number.
|
|
240
|
+
|
|
241
|
+
```c
|
|
242
|
+
#include "stdlib/complex/float64.h"
|
|
243
|
+
#include <node_api.h>
|
|
244
|
+
|
|
245
|
+
// ...
|
|
246
|
+
|
|
247
|
+
static double fcn( const stdlib_complex128_t x ) {
|
|
248
|
+
// ...
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// ...
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Receives JavaScript callback invocation data.
|
|
255
|
+
*
|
|
256
|
+
* @param env environment under which the function is invoked
|
|
257
|
+
* @param info callback data
|
|
258
|
+
* @return Node-API value
|
|
259
|
+
*/
|
|
260
|
+
napi_value addon( napi_env env, napi_callback_info info ) {
|
|
261
|
+
return stdlib_math_base_napi_z_d( env, info, fcn );
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// ...
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
The function accepts the following arguments:
|
|
268
|
+
|
|
269
|
+
- **env**: `[in] napi_env` environment under which the function is invoked.
|
|
270
|
+
- **info**: `[in] napi_callback_info` callback data.
|
|
271
|
+
- **fcn**: `[in] double (*fcn)( stdlib_complex128_t )` unary function.
|
|
272
|
+
|
|
273
|
+
```c
|
|
274
|
+
void stdlib_math_base_napi_z_d( napi_env env, napi_callback_info info, double (*fcn)( stdlib_complex128_t ) );
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
#### stdlib_math_base_napi_c_c( env, info, fcn )
|
|
278
|
+
|
|
279
|
+
Invokes a unary function accepting and returning single-precision complex floating-point numbers.
|
|
280
|
+
|
|
281
|
+
```c
|
|
282
|
+
#include "stdlib/complex/float32.h"
|
|
283
|
+
#include <node_api.h>
|
|
284
|
+
|
|
285
|
+
// ...
|
|
286
|
+
|
|
287
|
+
static stdlib_complex64_t identity( const stdlib_complex64_t x ) {
|
|
288
|
+
return x;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// ...
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Receives JavaScript callback invocation data.
|
|
295
|
+
*
|
|
296
|
+
* @param env environment under which the function is invoked
|
|
297
|
+
* @param info callback data
|
|
298
|
+
* @return Node-API value
|
|
299
|
+
*/
|
|
300
|
+
napi_value addon( napi_env env, napi_callback_info info ) {
|
|
301
|
+
return stdlib_math_base_napi_c_c( env, info, identity );
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// ...
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
The function accepts the following arguments:
|
|
308
|
+
|
|
309
|
+
- **env**: `[in] napi_env` environment under which the function is invoked.
|
|
310
|
+
- **info**: `[in] napi_callback_info` callback data.
|
|
311
|
+
- **fcn**: `[in] stdlib_complex64_t (*fcn)( stdlib_complex64_t )` unary function.
|
|
312
|
+
|
|
313
|
+
```c
|
|
314
|
+
void stdlib_math_base_napi_c_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t ) );
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
#### stdlib_math_base_napi_c_f( env, info, fcn )
|
|
318
|
+
|
|
319
|
+
Invokes a unary function accepting a single-precision complex floating-point number and returning a single-precision floating-point number.
|
|
320
|
+
|
|
321
|
+
```c
|
|
322
|
+
#include "stdlib/complex/float32.h"
|
|
323
|
+
#include <node_api.h>
|
|
324
|
+
|
|
325
|
+
// ...
|
|
326
|
+
|
|
327
|
+
static float fcn( const stdlib_complex64_t x ) {
|
|
328
|
+
// ...
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// ...
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Receives JavaScript callback invocation data.
|
|
335
|
+
*
|
|
336
|
+
* @param env environment under which the function is invoked
|
|
337
|
+
* @param info callback data
|
|
338
|
+
* @return Node-API value
|
|
339
|
+
*/
|
|
340
|
+
napi_value addon( napi_env env, napi_callback_info info ) {
|
|
341
|
+
return stdlib_math_base_napi_c_f( env, info, fcn );
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ...
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
The function accepts the following arguments:
|
|
348
|
+
|
|
349
|
+
- **env**: `[in] napi_env` environment under which the function is invoked.
|
|
350
|
+
- **info**: `[in] napi_callback_info` callback data.
|
|
351
|
+
- **fcn**: `[in] float (*fcn)( stdlib_complex64_t )` unary function.
|
|
352
|
+
|
|
353
|
+
```c
|
|
354
|
+
void stdlib_math_base_napi_c_f( napi_env env, napi_callback_info info, float (*fcn)( stdlib_complex64_t ) );
|
|
355
|
+
```
|
|
356
|
+
|
|
207
357
|
#### stdlib_math_base_napi_i_i( env, info, fcn )
|
|
208
358
|
|
|
209
359
|
Invokes a unary function accepting and returning 32-bit signed integers.
|
|
@@ -286,6 +436,116 @@ The macro expects the following arguments:
|
|
|
286
436
|
|
|
287
437
|
When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.
|
|
288
438
|
|
|
439
|
+
#### STDLIB_MATH_BASE_NAPI_MODULE_Z_Z( fcn )
|
|
440
|
+
|
|
441
|
+
Macro for registering a Node-API module exporting an interface for invoking a unary function accepting and returning double-precision complex floating-point numbers.
|
|
442
|
+
|
|
443
|
+
```c
|
|
444
|
+
#include "stdlib/complex/float64.h"
|
|
445
|
+
#include "stdlib/complex/reim.h"
|
|
446
|
+
|
|
447
|
+
static stdlib_complex128_t scale( const stdlib_complex128_t x ) {
|
|
448
|
+
double re;
|
|
449
|
+
double im;
|
|
450
|
+
|
|
451
|
+
stdlib_reim( x, &re, &im );
|
|
452
|
+
|
|
453
|
+
re *= 10.0;
|
|
454
|
+
im *= 10.0;
|
|
455
|
+
|
|
456
|
+
return stdlib_complex128( re, im );
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// ...
|
|
460
|
+
|
|
461
|
+
// Register a Node-API module:
|
|
462
|
+
STDLIB_MATH_BASE_NAPI_MODULE_Z_Z( scale );
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
The macro expects the following arguments:
|
|
466
|
+
|
|
467
|
+
- **fcn**: `stdlib_complex128_t (*fcn)( stdlib_complex128_t )` unary function.
|
|
468
|
+
|
|
469
|
+
When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.
|
|
470
|
+
|
|
471
|
+
#### STDLIB_MATH_BASE_NAPI_MODULE_Z_D( fcn )
|
|
472
|
+
|
|
473
|
+
Macro for registering a Node-API module exporting an interface for invoking a unary function accepting a double-precision complex floating-point number and returning a double-precision floating-point number.
|
|
474
|
+
|
|
475
|
+
```c
|
|
476
|
+
#include "stdlib/complex/float64.h"
|
|
477
|
+
|
|
478
|
+
static double fcn( const stdlib_complex128_t x ) {
|
|
479
|
+
// ...
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// ...
|
|
483
|
+
|
|
484
|
+
// Register a Node-API module:
|
|
485
|
+
STDLIB_MATH_BASE_NAPI_MODULE_Z_D( fcn );
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
The macro expects the following arguments:
|
|
489
|
+
|
|
490
|
+
- **fcn**: `double (*fcn)( stdlib_complex128_t )` unary function.
|
|
491
|
+
|
|
492
|
+
When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.
|
|
493
|
+
|
|
494
|
+
#### STDLIB_MATH_BASE_NAPI_MODULE_C_C( fcn )
|
|
495
|
+
|
|
496
|
+
Macro for registering a Node-API module exporting an interface for invoking a unary function accepting and returning single-precision complex floating-point numbers.
|
|
497
|
+
|
|
498
|
+
```c
|
|
499
|
+
#include "stdlib/complex/float32.h"
|
|
500
|
+
#include "stdlib/complex/reimf.h"
|
|
501
|
+
|
|
502
|
+
static stdlib_complex64_t scale( const stdlib_complex64_t x ) {
|
|
503
|
+
float re;
|
|
504
|
+
float im;
|
|
505
|
+
|
|
506
|
+
stdlib_reimf( x, &re, &im );
|
|
507
|
+
|
|
508
|
+
re *= 10.0f;
|
|
509
|
+
im *= 10.0f;
|
|
510
|
+
|
|
511
|
+
return stdlib_complex64( re, im );
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// ...
|
|
515
|
+
|
|
516
|
+
// Register a Node-API module:
|
|
517
|
+
STDLIB_MATH_BASE_NAPI_MODULE_C_C( scale );
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
The macro expects the following arguments:
|
|
521
|
+
|
|
522
|
+
- **fcn**: `stdlib_complex64_t (*fcn)( stdlib_complex64_t )` unary function.
|
|
523
|
+
|
|
524
|
+
When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.
|
|
525
|
+
|
|
526
|
+
#### STDLIB_MATH_BASE_NAPI_MODULE_C_F( fcn )
|
|
527
|
+
|
|
528
|
+
Macro for registering a Node-API module exporting an interface for invoking a unary function accepting a single-precision complex floating-point number and returning a single-precision floating-point number.
|
|
529
|
+
|
|
530
|
+
```c
|
|
531
|
+
#include "stdlib/complex/float32.h"
|
|
532
|
+
|
|
533
|
+
static float fcn( const stdlib_complex64_t x ) {
|
|
534
|
+
// ...
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// ...
|
|
538
|
+
|
|
539
|
+
// Register a Node-API module:
|
|
540
|
+
STDLIB_MATH_BASE_NAPI_MODULE_C_F( fcn );
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
The macro expects the following arguments:
|
|
544
|
+
|
|
545
|
+
- **fcn**: `float (*fcn)( stdlib_complex64_t )` unary function.
|
|
546
|
+
|
|
547
|
+
When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.
|
|
548
|
+
|
|
289
549
|
#### STDLIB_MATH_BASE_NAPI_MODULE_I_I( fcn )
|
|
290
550
|
|
|
291
551
|
Macro for registering a Node-API module exporting an interface for invoking a unary function accepting and returning 32-bit signed integers.
|
|
@@ -321,7 +581,7 @@ When used, this macro should be used **instead of** `NAPI_MODULE`. The macro inc
|
|
|
321
581
|
|
|
322
582
|
- The C-API functions expect that the callback `info` argument provides access to the following JavaScript arguments:
|
|
323
583
|
|
|
324
|
-
-
|
|
584
|
+
- **x**: input value.
|
|
325
585
|
|
|
326
586
|
</section>
|
|
327
587
|
|
|
@@ -347,6 +607,14 @@ When used, this macro should be used **instead of** `NAPI_MODULE`. The macro inc
|
|
|
347
607
|
|
|
348
608
|
<!-- /.references -->
|
|
349
609
|
|
|
610
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
611
|
+
|
|
612
|
+
<section class="related">
|
|
613
|
+
|
|
614
|
+
</section>
|
|
615
|
+
|
|
616
|
+
<!-- /.related -->
|
|
617
|
+
|
|
350
618
|
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
351
619
|
|
|
352
620
|
|
|
@@ -373,7 +641,7 @@ See [LICENSE][stdlib-license].
|
|
|
373
641
|
|
|
374
642
|
## Copyright
|
|
375
643
|
|
|
376
|
-
Copyright © 2016-
|
|
644
|
+
Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors].
|
|
377
645
|
|
|
378
646
|
</section>
|
|
379
647
|
|
|
@@ -392,9 +660,20 @@ Copyright © 2016-2021. The Stdlib [Authors][stdlib-authors].
|
|
|
392
660
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-napi-unary/main.svg
|
|
393
661
|
[coverage-url]: https://codecov.io/github/stdlib-js/math-base-napi-unary?branch=main
|
|
394
662
|
|
|
663
|
+
<!--
|
|
664
|
+
|
|
395
665
|
[dependencies-image]: https://img.shields.io/david/stdlib-js/math-base-napi-unary.svg
|
|
396
666
|
[dependencies-url]: https://david-dm.org/stdlib-js/math-base-napi-unary/main
|
|
397
667
|
|
|
668
|
+
-->
|
|
669
|
+
|
|
670
|
+
[umd]: https://github.com/umdjs/umd
|
|
671
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
672
|
+
|
|
673
|
+
[deno-url]: https://github.com/stdlib-js/math-base-napi-unary/tree/deno
|
|
674
|
+
[umd-url]: https://github.com/stdlib-js/math-base-napi-unary/tree/umd
|
|
675
|
+
[esm-url]: https://github.com/stdlib-js/math-base-napi-unary/tree/esm
|
|
676
|
+
|
|
398
677
|
[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
|
|
399
678
|
[chat-url]: https://gitter.im/stdlib-js/stdlib/
|
|
400
679
|
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
#ifndef STDLIB_MATH_BASE_NAPI_UNARY_H
|
|
20
20
|
#define STDLIB_MATH_BASE_NAPI_UNARY_H
|
|
21
21
|
|
|
22
|
+
#include "stdlib/complex/float32.h"
|
|
23
|
+
#include "stdlib/complex/float64.h"
|
|
22
24
|
#include <node_api.h>
|
|
23
25
|
#include <assert.h>
|
|
24
26
|
#include <stdint.h>
|
|
@@ -103,6 +105,192 @@
|
|
|
103
105
|
}; \
|
|
104
106
|
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_f_f_init )
|
|
105
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Macro for registering a Node-API module exporting an interface invoking a unary function accepting and returning double-precision complex floating-point numbers.
|
|
110
|
+
*
|
|
111
|
+
* @param fcn unary function
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* #include "stdlib/complex/float64.h"
|
|
115
|
+
* #include "stdlib/complex/reim.h"
|
|
116
|
+
*
|
|
117
|
+
* static stdlib_complex128_t scale( const stdlib_complex128_t x ) {
|
|
118
|
+
* double re;
|
|
119
|
+
* double im;
|
|
120
|
+
*
|
|
121
|
+
* stdlib_reim( x, &re, &im );
|
|
122
|
+
*
|
|
123
|
+
* re *= 10.0;
|
|
124
|
+
* im *= 10.0;
|
|
125
|
+
*
|
|
126
|
+
* return stdlib_complex128( re, im );
|
|
127
|
+
* }
|
|
128
|
+
*
|
|
129
|
+
* // ...
|
|
130
|
+
*
|
|
131
|
+
* // Register a Node-API module:
|
|
132
|
+
* STDLIB_MATH_BASE_NAPI_MODULE_Z_Z( scale );
|
|
133
|
+
*/
|
|
134
|
+
#define STDLIB_MATH_BASE_NAPI_MODULE_Z_Z( fcn ) \
|
|
135
|
+
static napi_value stdlib_math_base_napi_z_z_wrapper( \
|
|
136
|
+
napi_env env, \
|
|
137
|
+
napi_callback_info info \
|
|
138
|
+
) { \
|
|
139
|
+
return stdlib_math_base_napi_z_z( env, info, fcn ); \
|
|
140
|
+
}; \
|
|
141
|
+
static napi_value stdlib_math_base_napi_z_z_init( \
|
|
142
|
+
napi_env env, \
|
|
143
|
+
napi_value exports \
|
|
144
|
+
) { \
|
|
145
|
+
napi_value fcn; \
|
|
146
|
+
napi_status status = napi_create_function( \
|
|
147
|
+
env, \
|
|
148
|
+
"exports", \
|
|
149
|
+
NAPI_AUTO_LENGTH, \
|
|
150
|
+
stdlib_math_base_napi_z_z_wrapper, \
|
|
151
|
+
NULL, \
|
|
152
|
+
&fcn \
|
|
153
|
+
); \
|
|
154
|
+
assert( status == napi_ok ); \
|
|
155
|
+
return fcn; \
|
|
156
|
+
}; \
|
|
157
|
+
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_z_z_init )
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Macro for registering a Node-API module exporting an interface invoking a unary function accepting a double-precision complex floating-point number and returning a double-precision floating-point number.
|
|
161
|
+
*
|
|
162
|
+
* @param fcn unary function
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* #include "stdlib/complex/float64.h"
|
|
166
|
+
*
|
|
167
|
+
* static double fcn( const stdlib_complex128_t x ) {
|
|
168
|
+
* // ...
|
|
169
|
+
* }
|
|
170
|
+
*
|
|
171
|
+
* // ...
|
|
172
|
+
*
|
|
173
|
+
* // Register a Node-API module:
|
|
174
|
+
* STDLIB_MATH_BASE_NAPI_MODULE_Z_D( fcn );
|
|
175
|
+
*/
|
|
176
|
+
#define STDLIB_MATH_BASE_NAPI_MODULE_Z_D( fcn ) \
|
|
177
|
+
static napi_value stdlib_math_base_napi_z_d_wrapper( \
|
|
178
|
+
napi_env env, \
|
|
179
|
+
napi_callback_info info \
|
|
180
|
+
) { \
|
|
181
|
+
return stdlib_math_base_napi_z_d( env, info, fcn ); \
|
|
182
|
+
}; \
|
|
183
|
+
static napi_value stdlib_math_base_napi_z_d_init( \
|
|
184
|
+
napi_env env, \
|
|
185
|
+
napi_value exports \
|
|
186
|
+
) { \
|
|
187
|
+
napi_value fcn; \
|
|
188
|
+
napi_status status = napi_create_function( \
|
|
189
|
+
env, \
|
|
190
|
+
"exports", \
|
|
191
|
+
NAPI_AUTO_LENGTH, \
|
|
192
|
+
stdlib_math_base_napi_z_d_wrapper, \
|
|
193
|
+
NULL, \
|
|
194
|
+
&fcn \
|
|
195
|
+
); \
|
|
196
|
+
assert( status == napi_ok ); \
|
|
197
|
+
return fcn; \
|
|
198
|
+
}; \
|
|
199
|
+
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_z_d_init )
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Macro for registering a Node-API module exporting an interface invoking a unary function accepting and returning single-precision complex floating-point numbers.
|
|
203
|
+
*
|
|
204
|
+
* @param fcn unary function
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* #include "stdlib/complex/float32.h"
|
|
208
|
+
* #include "stdlib/complex/reimf.h"
|
|
209
|
+
*
|
|
210
|
+
* static stdlib_complex64_t scale( const stdlib_complex64_t x ) {
|
|
211
|
+
* float re;
|
|
212
|
+
* float im;
|
|
213
|
+
*
|
|
214
|
+
* stdlib_reimf( x, &re, &im );
|
|
215
|
+
*
|
|
216
|
+
* re *= 10.0f;
|
|
217
|
+
* im *= 10.0f;
|
|
218
|
+
*
|
|
219
|
+
* return stdlib_complex64( re, im );
|
|
220
|
+
* }
|
|
221
|
+
*
|
|
222
|
+
* // ...
|
|
223
|
+
*
|
|
224
|
+
* // Register a Node-API module:
|
|
225
|
+
* STDLIB_MATH_BASE_NAPI_MODULE_C_C( scale );
|
|
226
|
+
*/
|
|
227
|
+
#define STDLIB_MATH_BASE_NAPI_MODULE_C_C( fcn ) \
|
|
228
|
+
static napi_value stdlib_math_base_napi_c_c_wrapper( \
|
|
229
|
+
napi_env env, \
|
|
230
|
+
napi_callback_info info \
|
|
231
|
+
) { \
|
|
232
|
+
return stdlib_math_base_napi_c_c( env, info, fcn ); \
|
|
233
|
+
}; \
|
|
234
|
+
static napi_value stdlib_math_base_napi_c_c_init( \
|
|
235
|
+
napi_env env, \
|
|
236
|
+
napi_value exports \
|
|
237
|
+
) { \
|
|
238
|
+
napi_value fcn; \
|
|
239
|
+
napi_status status = napi_create_function( \
|
|
240
|
+
env, \
|
|
241
|
+
"exports", \
|
|
242
|
+
NAPI_AUTO_LENGTH, \
|
|
243
|
+
stdlib_math_base_napi_c_c_wrapper, \
|
|
244
|
+
NULL, \
|
|
245
|
+
&fcn \
|
|
246
|
+
); \
|
|
247
|
+
assert( status == napi_ok ); \
|
|
248
|
+
return fcn; \
|
|
249
|
+
}; \
|
|
250
|
+
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_c_c_init )
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Macro for registering a Node-API module exporting an interface invoking a unary function accepting a single-precision complex floating-point number and returning a single-precision floating-point number.
|
|
254
|
+
*
|
|
255
|
+
* @param fcn unary function
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* #include "stdlib/complex/float32.h"
|
|
259
|
+
*
|
|
260
|
+
* static float fcn( const stdlib_complex64_t x ) {
|
|
261
|
+
* // ...
|
|
262
|
+
* }
|
|
263
|
+
*
|
|
264
|
+
* // ...
|
|
265
|
+
*
|
|
266
|
+
* // Register a Node-API module:
|
|
267
|
+
* STDLIB_MATH_BASE_NAPI_MODULE_C_F( fcn );
|
|
268
|
+
*/
|
|
269
|
+
#define STDLIB_MATH_BASE_NAPI_MODULE_C_F( fcn ) \
|
|
270
|
+
static napi_value stdlib_math_base_napi_c_f_wrapper( \
|
|
271
|
+
napi_env env, \
|
|
272
|
+
napi_callback_info info \
|
|
273
|
+
) { \
|
|
274
|
+
return stdlib_math_base_napi_c_f( env, info, fcn ); \
|
|
275
|
+
}; \
|
|
276
|
+
static napi_value stdlib_math_base_napi_c_f_init( \
|
|
277
|
+
napi_env env, \
|
|
278
|
+
napi_value exports \
|
|
279
|
+
) { \
|
|
280
|
+
napi_value fcn; \
|
|
281
|
+
napi_status status = napi_create_function( \
|
|
282
|
+
env, \
|
|
283
|
+
"exports", \
|
|
284
|
+
NAPI_AUTO_LENGTH, \
|
|
285
|
+
stdlib_math_base_napi_c_f_wrapper, \
|
|
286
|
+
NULL, \
|
|
287
|
+
&fcn \
|
|
288
|
+
); \
|
|
289
|
+
assert( status == napi_ok ); \
|
|
290
|
+
return fcn; \
|
|
291
|
+
}; \
|
|
292
|
+
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_c_f_init )
|
|
293
|
+
|
|
106
294
|
/**
|
|
107
295
|
* Macro for registering a Node-API module exporting an interface invoking a unary function accepting and returning 32-bit signed integers.
|
|
108
296
|
*
|
|
@@ -162,6 +350,26 @@ napi_value stdlib_math_base_napi_d_d( napi_env env, napi_callback_info info, dou
|
|
|
162
350
|
*/
|
|
163
351
|
napi_value stdlib_math_base_napi_f_f( napi_env env, napi_callback_info info, float (*fcn)( float ) );
|
|
164
352
|
|
|
353
|
+
/**
|
|
354
|
+
* Invokes a unary function accepting and returning double-precision complex floating-point numbers.
|
|
355
|
+
*/
|
|
356
|
+
napi_value stdlib_math_base_napi_z_z( napi_env env, napi_callback_info info, stdlib_complex128_t (*fcn)( stdlib_complex128_t ) );
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Invokes a unary function accepting a double-precision complex floating-point number and returning a double-precision floating-point number.
|
|
360
|
+
*/
|
|
361
|
+
napi_value stdlib_math_base_napi_z_d( napi_env env, napi_callback_info info, double (*fcn)( stdlib_complex128_t ) );
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Invokes a unary function accepting and returning single-precision complex floating-point numbers.
|
|
365
|
+
*/
|
|
366
|
+
napi_value stdlib_math_base_napi_c_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t ) );
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Invokes a unary function accepting a single-precision complex floating-point number and returning a single-precision floating-point number.
|
|
370
|
+
*/
|
|
371
|
+
napi_value stdlib_math_base_napi_c_f( napi_env env, napi_callback_info info, float (*fcn)( stdlib_complex64_t ) );
|
|
372
|
+
|
|
165
373
|
/**
|
|
166
374
|
* Invokes a unary function accepting and returning 32-bit signed integers.
|
|
167
375
|
*/
|
package/manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/math-base-napi-unary",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "C APIs for registering a Node-API module exporting an interface for invoking a unary numerical function.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -41,6 +41,10 @@
|
|
|
41
41
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
+
"@stdlib/complex-float32": "^0.0.x",
|
|
45
|
+
"@stdlib/complex-float64": "^0.0.x",
|
|
46
|
+
"@stdlib/complex-reim": "^0.0.x",
|
|
47
|
+
"@stdlib/complex-reimf": "^0.0.x",
|
|
44
48
|
"@stdlib/utils-library-manifest": "^0.0.x"
|
|
45
49
|
},
|
|
46
50
|
"devDependencies": {
|
package/src/main.c
CHANGED
|
@@ -17,9 +17,14 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
#include "stdlib/math/base/napi/unary.h"
|
|
20
|
+
#include "stdlib/complex/float64.h"
|
|
21
|
+
#include "stdlib/complex/float32.h"
|
|
22
|
+
#include "stdlib/complex/reim.h"
|
|
23
|
+
#include "stdlib/complex/reimf.h"
|
|
20
24
|
#include <node_api.h>
|
|
21
25
|
#include <stdint.h>
|
|
22
26
|
#include <assert.h>
|
|
27
|
+
#include <stdbool.h>
|
|
23
28
|
|
|
24
29
|
/**
|
|
25
30
|
* Invokes a unary function accepting and returning double-precision floating-point numbers.
|
|
@@ -117,6 +122,388 @@ napi_value stdlib_math_base_napi_f_f( napi_env env, napi_callback_info info, flo
|
|
|
117
122
|
return v;
|
|
118
123
|
}
|
|
119
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Invokes a unary function accepting and returning double-precision complex floating-point numbers.
|
|
127
|
+
*
|
|
128
|
+
* ## Notes
|
|
129
|
+
*
|
|
130
|
+
* - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
|
|
131
|
+
*
|
|
132
|
+
* - `x`: input value.
|
|
133
|
+
*
|
|
134
|
+
* @param env environment under which the function is invoked
|
|
135
|
+
* @param info callback data
|
|
136
|
+
* @param fcn unary function
|
|
137
|
+
* @return function return value as a Node-API complex-like object
|
|
138
|
+
*/
|
|
139
|
+
napi_value stdlib_math_base_napi_z_z( napi_env env, napi_callback_info info, stdlib_complex128_t (*fcn)( stdlib_complex128_t ) ) {
|
|
140
|
+
napi_status status;
|
|
141
|
+
|
|
142
|
+
size_t argc = 1;
|
|
143
|
+
napi_value argv[ 1 ];
|
|
144
|
+
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
|
|
145
|
+
assert( status == napi_ok );
|
|
146
|
+
|
|
147
|
+
if ( argc < 1 ) {
|
|
148
|
+
status = napi_throw_error( env, NULL, "invalid invocation. Must provide a complex number." );
|
|
149
|
+
assert( status == napi_ok );
|
|
150
|
+
return NULL;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
bool hprop;
|
|
154
|
+
status = napi_has_named_property( env, argv[ 0 ], "re", &hprop );
|
|
155
|
+
assert( status == napi_ok );
|
|
156
|
+
if ( !hprop ) {
|
|
157
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have a real component." );
|
|
158
|
+
assert( status == napi_ok );
|
|
159
|
+
return NULL;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
napi_value xre;
|
|
163
|
+
status = napi_get_named_property( env, argv[ 0 ], "re", &xre );
|
|
164
|
+
assert( status == napi_ok );
|
|
165
|
+
|
|
166
|
+
napi_valuetype xretype;
|
|
167
|
+
status = napi_typeof( env, xre, &xretype );
|
|
168
|
+
assert( status == napi_ok );
|
|
169
|
+
if ( xretype != napi_number ) {
|
|
170
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have a real component which is a number." );
|
|
171
|
+
assert( status == napi_ok );
|
|
172
|
+
return NULL;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
status = napi_has_named_property( env, argv[ 0 ], "im", &hprop );
|
|
176
|
+
assert( status == napi_ok );
|
|
177
|
+
if ( !hprop ) {
|
|
178
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have an imaginary component." );
|
|
179
|
+
assert( status == napi_ok );
|
|
180
|
+
return NULL;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
napi_value xim;
|
|
184
|
+
status = napi_get_named_property( env, argv[ 0 ], "im", &xim );
|
|
185
|
+
assert( status == napi_ok );
|
|
186
|
+
|
|
187
|
+
napi_valuetype ximtype;
|
|
188
|
+
status = napi_typeof( env, xim, &ximtype );
|
|
189
|
+
assert( status == napi_ok );
|
|
190
|
+
if ( ximtype != napi_number ) {
|
|
191
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have an imaginary component which a number." );
|
|
192
|
+
assert( status == napi_ok );
|
|
193
|
+
return NULL;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
double re0;
|
|
197
|
+
status = napi_get_value_double( env, xre, &re0 );
|
|
198
|
+
assert( status == napi_ok );
|
|
199
|
+
|
|
200
|
+
double im0;
|
|
201
|
+
status = napi_get_value_double( env, xim, &im0 );
|
|
202
|
+
assert( status == napi_ok );
|
|
203
|
+
|
|
204
|
+
stdlib_complex128_t v = fcn( stdlib_complex128( re0, im0 ) );
|
|
205
|
+
double re;
|
|
206
|
+
double im;
|
|
207
|
+
stdlib_reim( v, &re, &im );
|
|
208
|
+
|
|
209
|
+
napi_value obj;
|
|
210
|
+
status = napi_create_object( env, &obj );
|
|
211
|
+
assert( status == napi_ok );
|
|
212
|
+
|
|
213
|
+
napi_value vre;
|
|
214
|
+
status = napi_create_double( env, re, &vre );
|
|
215
|
+
assert( status == napi_ok );
|
|
216
|
+
|
|
217
|
+
status = napi_set_named_property( env, obj, "re", vre );
|
|
218
|
+
assert( status == napi_ok );
|
|
219
|
+
|
|
220
|
+
napi_value vim;
|
|
221
|
+
status = napi_create_double( env, im, &vim );
|
|
222
|
+
assert( status == napi_ok );
|
|
223
|
+
|
|
224
|
+
status = napi_set_named_property( env, obj, "im", vim );
|
|
225
|
+
assert( status == napi_ok );
|
|
226
|
+
|
|
227
|
+
return obj;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Invokes a unary function accepting a double-precision complex floating-point number and returning a double-precision floating-point number.
|
|
232
|
+
*
|
|
233
|
+
* ## Notes
|
|
234
|
+
*
|
|
235
|
+
* - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
|
|
236
|
+
*
|
|
237
|
+
* - `x`: input value.
|
|
238
|
+
*
|
|
239
|
+
* @param env environment under which the function is invoked
|
|
240
|
+
* @param info callback data
|
|
241
|
+
* @param fcn unary function
|
|
242
|
+
* @return function return value as a Node-API complex-like object
|
|
243
|
+
*/
|
|
244
|
+
napi_value stdlib_math_base_napi_z_d( napi_env env, napi_callback_info info, double (*fcn)( stdlib_complex128_t ) ) {
|
|
245
|
+
napi_status status;
|
|
246
|
+
|
|
247
|
+
size_t argc = 1;
|
|
248
|
+
napi_value argv[ 1 ];
|
|
249
|
+
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
|
|
250
|
+
assert( status == napi_ok );
|
|
251
|
+
|
|
252
|
+
if ( argc < 1 ) {
|
|
253
|
+
status = napi_throw_error( env, NULL, "invalid invocation. Must provide a complex number." );
|
|
254
|
+
assert( status == napi_ok );
|
|
255
|
+
return NULL;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
bool hprop;
|
|
259
|
+
status = napi_has_named_property( env, argv[ 0 ], "re", &hprop );
|
|
260
|
+
assert( status == napi_ok );
|
|
261
|
+
if ( !hprop ) {
|
|
262
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have a real component." );
|
|
263
|
+
assert( status == napi_ok );
|
|
264
|
+
return NULL;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
napi_value xre;
|
|
268
|
+
status = napi_get_named_property( env, argv[ 0 ], "re", &xre );
|
|
269
|
+
assert( status == napi_ok );
|
|
270
|
+
|
|
271
|
+
napi_valuetype xretype;
|
|
272
|
+
status = napi_typeof( env, xre, &xretype );
|
|
273
|
+
assert( status == napi_ok );
|
|
274
|
+
if ( xretype != napi_number ) {
|
|
275
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have a real component which is a number." );
|
|
276
|
+
assert( status == napi_ok );
|
|
277
|
+
return NULL;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
status = napi_has_named_property( env, argv[ 0 ], "im", &hprop );
|
|
281
|
+
assert( status == napi_ok );
|
|
282
|
+
if ( !hprop ) {
|
|
283
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have an imaginary component." );
|
|
284
|
+
assert( status == napi_ok );
|
|
285
|
+
return NULL;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
napi_value xim;
|
|
289
|
+
status = napi_get_named_property( env, argv[ 0 ], "im", &xim );
|
|
290
|
+
assert( status == napi_ok );
|
|
291
|
+
|
|
292
|
+
napi_valuetype ximtype;
|
|
293
|
+
status = napi_typeof( env, xim, &ximtype );
|
|
294
|
+
assert( status == napi_ok );
|
|
295
|
+
if ( ximtype != napi_number ) {
|
|
296
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have an imaginary component which a number." );
|
|
297
|
+
assert( status == napi_ok );
|
|
298
|
+
return NULL;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
double re;
|
|
302
|
+
status = napi_get_value_double( env, xre, &re );
|
|
303
|
+
assert( status == napi_ok );
|
|
304
|
+
|
|
305
|
+
double im;
|
|
306
|
+
status = napi_get_value_double( env, xim, &im );
|
|
307
|
+
assert( status == napi_ok );
|
|
308
|
+
|
|
309
|
+
napi_value v;
|
|
310
|
+
status = napi_create_double( env, fcn( stdlib_complex128( re, im ) ), &v );
|
|
311
|
+
assert( status == napi_ok );
|
|
312
|
+
|
|
313
|
+
return v;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Invokes a unary function accepting and returning single-precision complex floating-point numbers.
|
|
318
|
+
*
|
|
319
|
+
* ## Notes
|
|
320
|
+
*
|
|
321
|
+
* - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
|
|
322
|
+
*
|
|
323
|
+
* - `x`: input value.
|
|
324
|
+
*
|
|
325
|
+
* @param env environment under which the function is invoked
|
|
326
|
+
* @param info callback data
|
|
327
|
+
* @param fcn unary function
|
|
328
|
+
* @return function return value as a Node-API complex-like object
|
|
329
|
+
*/
|
|
330
|
+
napi_value stdlib_math_base_napi_c_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t ) ) {
|
|
331
|
+
napi_status status;
|
|
332
|
+
|
|
333
|
+
size_t argc = 1;
|
|
334
|
+
napi_value argv[ 1 ];
|
|
335
|
+
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
|
|
336
|
+
assert( status == napi_ok );
|
|
337
|
+
|
|
338
|
+
if ( argc < 1 ) {
|
|
339
|
+
status = napi_throw_error( env, NULL, "invalid invocation. Must provide a complex number." );
|
|
340
|
+
assert( status == napi_ok );
|
|
341
|
+
return NULL;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
bool hprop;
|
|
345
|
+
status = napi_has_named_property( env, argv[ 0 ], "re", &hprop );
|
|
346
|
+
assert( status == napi_ok );
|
|
347
|
+
if ( !hprop ) {
|
|
348
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have a real component." );
|
|
349
|
+
assert( status == napi_ok );
|
|
350
|
+
return NULL;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
napi_value xre;
|
|
354
|
+
status = napi_get_named_property( env, argv[ 0 ], "re", &xre );
|
|
355
|
+
assert( status == napi_ok );
|
|
356
|
+
|
|
357
|
+
napi_valuetype xretype;
|
|
358
|
+
status = napi_typeof( env, xre, &xretype );
|
|
359
|
+
assert( status == napi_ok );
|
|
360
|
+
if ( xretype != napi_number ) {
|
|
361
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have a real component which is a number." );
|
|
362
|
+
assert( status == napi_ok );
|
|
363
|
+
return NULL;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
status = napi_has_named_property( env, argv[ 0 ], "im", &hprop );
|
|
367
|
+
assert( status == napi_ok );
|
|
368
|
+
if ( !hprop ) {
|
|
369
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have an imaginary component." );
|
|
370
|
+
assert( status == napi_ok );
|
|
371
|
+
return NULL;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
napi_value xim;
|
|
375
|
+
status = napi_get_named_property( env, argv[ 0 ], "im", &xim );
|
|
376
|
+
assert( status == napi_ok );
|
|
377
|
+
|
|
378
|
+
napi_valuetype ximtype;
|
|
379
|
+
status = napi_typeof( env, xim, &ximtype );
|
|
380
|
+
assert( status == napi_ok );
|
|
381
|
+
if ( ximtype != napi_number ) {
|
|
382
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have an imaginary component which a number." );
|
|
383
|
+
assert( status == napi_ok );
|
|
384
|
+
return NULL;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
double re0;
|
|
388
|
+
status = napi_get_value_double( env, xre, &re0 );
|
|
389
|
+
assert( status == napi_ok );
|
|
390
|
+
|
|
391
|
+
double im0;
|
|
392
|
+
status = napi_get_value_double( env, xim, &im0 );
|
|
393
|
+
assert( status == napi_ok );
|
|
394
|
+
|
|
395
|
+
stdlib_complex64_t v = fcn( stdlib_complex64( (float)re0, (float)im0 ) );
|
|
396
|
+
float re;
|
|
397
|
+
float im;
|
|
398
|
+
stdlib_reimf( v, &re, &im );
|
|
399
|
+
|
|
400
|
+
napi_value obj;
|
|
401
|
+
status = napi_create_object( env, &obj );
|
|
402
|
+
assert( status == napi_ok );
|
|
403
|
+
|
|
404
|
+
napi_value vre;
|
|
405
|
+
status = napi_create_double( env, (double)re, &vre );
|
|
406
|
+
assert( status == napi_ok );
|
|
407
|
+
|
|
408
|
+
status = napi_set_named_property( env, obj, "re", vre );
|
|
409
|
+
assert( status == napi_ok );
|
|
410
|
+
|
|
411
|
+
napi_value vim;
|
|
412
|
+
status = napi_create_double( env, (double)im, &vim );
|
|
413
|
+
assert( status == napi_ok );
|
|
414
|
+
|
|
415
|
+
status = napi_set_named_property( env, obj, "im", vim );
|
|
416
|
+
assert( status == napi_ok );
|
|
417
|
+
|
|
418
|
+
return obj;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Invokes a unary function accepting a single-precision complex floating-point number and returning a single-precision floating-point number.
|
|
423
|
+
*
|
|
424
|
+
* ## Notes
|
|
425
|
+
*
|
|
426
|
+
* - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
|
|
427
|
+
*
|
|
428
|
+
* - `x`: input value.
|
|
429
|
+
*
|
|
430
|
+
* @param env environment under which the function is invoked
|
|
431
|
+
* @param info callback data
|
|
432
|
+
* @param fcn unary function
|
|
433
|
+
* @return function return value as a Node-API complex-like object
|
|
434
|
+
*/
|
|
435
|
+
napi_value stdlib_math_base_napi_c_f( napi_env env, napi_callback_info info, float (*fcn)( stdlib_complex64_t ) ) {
|
|
436
|
+
napi_status status;
|
|
437
|
+
|
|
438
|
+
size_t argc = 1;
|
|
439
|
+
napi_value argv[ 1 ];
|
|
440
|
+
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
|
|
441
|
+
assert( status == napi_ok );
|
|
442
|
+
|
|
443
|
+
if ( argc < 1 ) {
|
|
444
|
+
status = napi_throw_error( env, NULL, "invalid invocation. Must provide a complex number." );
|
|
445
|
+
assert( status == napi_ok );
|
|
446
|
+
return NULL;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
bool hprop;
|
|
450
|
+
status = napi_has_named_property( env, argv[ 0 ], "re", &hprop );
|
|
451
|
+
assert( status == napi_ok );
|
|
452
|
+
if ( !hprop ) {
|
|
453
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have a real component." );
|
|
454
|
+
assert( status == napi_ok );
|
|
455
|
+
return NULL;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
napi_value xre;
|
|
459
|
+
status = napi_get_named_property( env, argv[ 0 ], "re", &xre );
|
|
460
|
+
assert( status == napi_ok );
|
|
461
|
+
|
|
462
|
+
napi_valuetype xretype;
|
|
463
|
+
status = napi_typeof( env, xre, &xretype );
|
|
464
|
+
assert( status == napi_ok );
|
|
465
|
+
if ( xretype != napi_number ) {
|
|
466
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have a real component which is a number." );
|
|
467
|
+
assert( status == napi_ok );
|
|
468
|
+
return NULL;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
status = napi_has_named_property( env, argv[ 0 ], "im", &hprop );
|
|
472
|
+
assert( status == napi_ok );
|
|
473
|
+
if ( !hprop ) {
|
|
474
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have an imaginary component." );
|
|
475
|
+
assert( status == napi_ok );
|
|
476
|
+
return NULL;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
napi_value xim;
|
|
480
|
+
status = napi_get_named_property( env, argv[ 0 ], "im", &xim );
|
|
481
|
+
assert( status == napi_ok );
|
|
482
|
+
|
|
483
|
+
napi_valuetype ximtype;
|
|
484
|
+
status = napi_typeof( env, xim, &ximtype );
|
|
485
|
+
assert( status == napi_ok );
|
|
486
|
+
if ( ximtype != napi_number ) {
|
|
487
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have an imaginary component which a number." );
|
|
488
|
+
assert( status == napi_ok );
|
|
489
|
+
return NULL;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
double re;
|
|
493
|
+
status = napi_get_value_double( env, xre, &re );
|
|
494
|
+
assert( status == napi_ok );
|
|
495
|
+
|
|
496
|
+
double im;
|
|
497
|
+
status = napi_get_value_double( env, xim, &im );
|
|
498
|
+
assert( status == napi_ok );
|
|
499
|
+
|
|
500
|
+
napi_value v;
|
|
501
|
+
status = napi_create_double( env, (double)fcn( stdlib_complex64( (float)re, (float)im ) ), &v );
|
|
502
|
+
assert( status == napi_ok );
|
|
503
|
+
|
|
504
|
+
return v;
|
|
505
|
+
}
|
|
506
|
+
|
|
120
507
|
/**
|
|
121
508
|
* Invokes a unary function accepting and returning 32-bit signed integers.
|
|
122
509
|
*
|
package/binding.gyp
DELETED
|
@@ -1,170 +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` file for building a Node.js native add-on.
|
|
18
|
-
#
|
|
19
|
-
# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md
|
|
20
|
-
# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md
|
|
21
|
-
{
|
|
22
|
-
# List of files to include in this file:
|
|
23
|
-
'includes': [
|
|
24
|
-
'./include.gypi',
|
|
25
|
-
],
|
|
26
|
-
|
|
27
|
-
# Define variables to be used throughout the configuration for all targets:
|
|
28
|
-
'variables': {
|
|
29
|
-
# Target name should match the add-on export name:
|
|
30
|
-
'addon_target_name%': 'addon',
|
|
31
|
-
|
|
32
|
-
# Set variables based on the host OS:
|
|
33
|
-
'conditions': [
|
|
34
|
-
[
|
|
35
|
-
'OS=="win"',
|
|
36
|
-
{
|
|
37
|
-
# Define the object file suffix:
|
|
38
|
-
'obj': 'obj',
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
# Define the object file suffix:
|
|
42
|
-
'obj': 'o',
|
|
43
|
-
}
|
|
44
|
-
], # end condition (OS=="win")
|
|
45
|
-
], # end conditions
|
|
46
|
-
}, # end variables
|
|
47
|
-
|
|
48
|
-
# Define compile targets:
|
|
49
|
-
'targets': [
|
|
50
|
-
|
|
51
|
-
# Target to generate an add-on:
|
|
52
|
-
{
|
|
53
|
-
# The target name should match the add-on export name:
|
|
54
|
-
'target_name': '<(addon_target_name)',
|
|
55
|
-
|
|
56
|
-
# Define dependencies:
|
|
57
|
-
'dependencies': [],
|
|
58
|
-
|
|
59
|
-
# Define directories which contain relevant include headers:
|
|
60
|
-
'include_dirs': [
|
|
61
|
-
# Local include directory:
|
|
62
|
-
'<@(include_dirs)',
|
|
63
|
-
],
|
|
64
|
-
|
|
65
|
-
# List of source files:
|
|
66
|
-
'sources': [
|
|
67
|
-
'<@(src_files)',
|
|
68
|
-
],
|
|
69
|
-
|
|
70
|
-
# Settings which should be applied when a target's object files are used as linker input:
|
|
71
|
-
'link_settings': {
|
|
72
|
-
# Define libraries:
|
|
73
|
-
'libraries': [
|
|
74
|
-
'<@(libraries)',
|
|
75
|
-
],
|
|
76
|
-
|
|
77
|
-
# Define library directories:
|
|
78
|
-
'library_dirs': [
|
|
79
|
-
'<@(library_dirs)',
|
|
80
|
-
],
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
# C/C++ compiler flags:
|
|
84
|
-
'cflags': [
|
|
85
|
-
# Enable commonly used warning options:
|
|
86
|
-
'-Wall',
|
|
87
|
-
|
|
88
|
-
# Aggressive optimization:
|
|
89
|
-
'-O3',
|
|
90
|
-
],
|
|
91
|
-
|
|
92
|
-
# C specific compiler flags:
|
|
93
|
-
'cflags_c': [
|
|
94
|
-
# Specify the C standard to which a program is expected to conform:
|
|
95
|
-
'-std=c99',
|
|
96
|
-
],
|
|
97
|
-
|
|
98
|
-
# C++ specific compiler flags:
|
|
99
|
-
'cflags_cpp': [
|
|
100
|
-
# Specify the C++ standard to which a program is expected to conform:
|
|
101
|
-
'-std=c++11',
|
|
102
|
-
],
|
|
103
|
-
|
|
104
|
-
# Linker flags:
|
|
105
|
-
'ldflags': [],
|
|
106
|
-
|
|
107
|
-
# Apply conditions based on the host OS:
|
|
108
|
-
'conditions': [
|
|
109
|
-
[
|
|
110
|
-
'OS=="mac"',
|
|
111
|
-
{
|
|
112
|
-
# Linker flags:
|
|
113
|
-
'ldflags': [
|
|
114
|
-
'-undefined dynamic_lookup',
|
|
115
|
-
'-Wl,-no-pie',
|
|
116
|
-
'-Wl,-search_paths_first',
|
|
117
|
-
],
|
|
118
|
-
},
|
|
119
|
-
], # end condition (OS=="mac")
|
|
120
|
-
[
|
|
121
|
-
'OS!="win"',
|
|
122
|
-
{
|
|
123
|
-
# C/C++ flags:
|
|
124
|
-
'cflags': [
|
|
125
|
-
# Generate platform-independent code:
|
|
126
|
-
'-fPIC',
|
|
127
|
-
],
|
|
128
|
-
},
|
|
129
|
-
], # end condition (OS!="win")
|
|
130
|
-
], # end conditions
|
|
131
|
-
}, # end target <(addon_target_name)
|
|
132
|
-
|
|
133
|
-
# Target to copy a generated add-on to a standard location:
|
|
134
|
-
{
|
|
135
|
-
'target_name': 'copy_addon',
|
|
136
|
-
|
|
137
|
-
# Declare that the output of this target is not linked:
|
|
138
|
-
'type': 'none',
|
|
139
|
-
|
|
140
|
-
# Define dependencies:
|
|
141
|
-
'dependencies': [
|
|
142
|
-
# Require that the add-on be generated before building this target:
|
|
143
|
-
'<(addon_target_name)',
|
|
144
|
-
],
|
|
145
|
-
|
|
146
|
-
# Define a list of actions:
|
|
147
|
-
'actions': [
|
|
148
|
-
{
|
|
149
|
-
'action_name': 'copy_addon',
|
|
150
|
-
'message': 'Copying addon...',
|
|
151
|
-
|
|
152
|
-
# Explicitly list the inputs in the command-line invocation below:
|
|
153
|
-
'inputs': [],
|
|
154
|
-
|
|
155
|
-
# Declare the expected outputs:
|
|
156
|
-
'outputs': [
|
|
157
|
-
'<(addon_output_dir)/<(addon_target_name).node',
|
|
158
|
-
],
|
|
159
|
-
|
|
160
|
-
# Define the command-line invocation:
|
|
161
|
-
'action': [
|
|
162
|
-
'cp',
|
|
163
|
-
'<(PRODUCT_DIR)/<(addon_target_name).node',
|
|
164
|
-
'<(addon_output_dir)/<(addon_target_name).node',
|
|
165
|
-
],
|
|
166
|
-
},
|
|
167
|
-
], # end actions
|
|
168
|
-
}, # end target copy_addon
|
|
169
|
-
], # end targets
|
|
170
|
-
}
|