@stdlib/math-base-napi-binary 0.0.4 → 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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2021 The Stdlib Authors.
1
+ Copyright (c) 2016-2022 The Stdlib Authors.
package/README.md CHANGED
@@ -20,9 +20,9 @@ limitations under the License.
20
20
 
21
21
  # binary
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
- > C APIs for registering an N-API module exporting interfaces for invoking binary numerical functions.
25
+ > C APIs for registering a Node-API module exporting interfaces for invoking binary numerical functions.
26
26
 
27
27
  <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
28
28
 
@@ -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-binary
117
- ```
118
-
119
- </section>
120
-
121
111
  <section class="usage">
122
112
 
123
113
  ### Usage
@@ -142,11 +132,11 @@ static double add( const double x, const double y ) {
142
132
  // ...
143
133
 
144
134
  /**
145
- * Receives JavaScript callback invocation data via N-API.
135
+ * Receives JavaScript callback invocation data.
146
136
  *
147
137
  * @param env environment under which the function is invoked
148
138
  * @param info callback data
149
- * @return N-API value
139
+ * @return Node-API value
150
140
  */
151
141
  napi_value addon( napi_env env, napi_callback_info info ) {
152
142
  return stdlib_math_base_napi_dd_d( env, info, add );
@@ -181,11 +171,11 @@ static float addf( const float x, const float y ) {
181
171
  // ...
182
172
 
183
173
  /**
184
- * Receives JavaScript callback invocation data via N-API.
174
+ * Receives JavaScript callback invocation data.
185
175
  *
186
176
  * @param env environment under which the function is invoked
187
177
  * @param info callback data
188
- * @return N-API value
178
+ * @return Node-API value
189
179
  */
190
180
  napi_value addon( napi_env env, napi_callback_info info ) {
191
181
  return stdlib_math_base_napi_ff_f( env, info, addf );
@@ -202,11 +192,120 @@ The function accepts the following arguments:
202
192
 
203
193
  ```c
204
194
  void stdlib_math_base_napi_ff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float ) );
195
+ ```de "stdlib/math/base/napi/binary.h"
196
+ ```
197
+
198
+ #### stdlib_math_base_napi_zz_z( env, info, fcn )
199
+
200
+ Invokes a binary function accepting and returning double-precision complex floating-point numbers.
201
+
202
+ ```c
203
+ #include "stdlib/complex/float64.h"
204
+ #include "stdlib/complex/reim.h"
205
+ #include <node_api.h>
206
+
207
+ // ...
208
+
209
+ static stdlib_complex128_t add( const stdlib_complex128_t x, const stdlib_complex128_t y ) {
210
+ double xre;
211
+ double xim;
212
+ double yre;
213
+ double yim;
214
+ double re;
215
+ double im;
216
+
217
+ stdlib_reim( x, &xre, &xim );
218
+ stdlib_reim( y, &yre, &yim );
219
+
220
+ re = xre + yre;
221
+ im = xim + yim;
222
+
223
+ return stdlib_complex128( re, im );
224
+ }
225
+
226
+ // ...
227
+
228
+ /**
229
+ * Receives JavaScript callback invocation data.
230
+ *
231
+ * @param env environment under which the function is invoked
232
+ * @param info callback data
233
+ * @return Node-API value
234
+ */
235
+ napi_value addon( napi_env env, napi_callback_info info ) {
236
+ return stdlib_math_base_napi_zz_z( env, info, add );
237
+ }
238
+
239
+ // ...
240
+ ```
241
+
242
+ The function accepts the following arguments:
243
+
244
+ - **env**: `[in] napi_env` environment under which the function is invoked.
245
+ - **info**: `[in] napi_callback_info` callback data.
246
+ - **fcn**: `[in] stdlib_complex128_t (*fcn)( stdlib_complex128_t, stdlib_complex128_t )` binary function.
247
+
248
+ ```c
249
+ void stdlib_math_base_napi_zz_z( napi_env env, napi_callback_info info, stdlib_complex128_t (*fcn)( stdlib_complex128_t, stdlib_complex128_t ) );
250
+ ```
251
+
252
+ #### stdlib_math_base_napi_cc_c( env, info, fcn )
253
+
254
+ Invokes a binary function accepting and returning single-precision complex floating-point numbers.
255
+
256
+ ```c
257
+ #include "stdlib/complex/float64.h"
258
+ #include "stdlib/complex/reim.h"
259
+ #include <node_api.h>
260
+
261
+ // ...
262
+
263
+ static stdlib_complex64_t add( const stdlib_complex64_t x, const stdlib_complex64_t y ) {
264
+ float xre;
265
+ float xim;
266
+ float yre;
267
+ float yim;
268
+ float re;
269
+ float im;
270
+
271
+ stdlib_reimf( x, &xre, &xim );
272
+ stdlib_reimf( y, &yre, &yim );
273
+
274
+ re = xre + yre;
275
+ im = xim + yim;
276
+
277
+ return stdlib_complex64( re, im );
278
+ }
279
+
280
+ // ...
281
+
282
+ /**
283
+ * Receives JavaScript callback invocation data.
284
+ *
285
+ * @param env environment under which the function is invoked
286
+ * @param info callback data
287
+ * @return Node-API value
288
+ */
289
+ napi_value addon( napi_env env, napi_callback_info info ) {
290
+ return stdlib_math_base_napi_cc_c( env, info, add );
291
+ }
292
+
293
+ // ...
294
+ ```
295
+
296
+ The function accepts the following arguments:
297
+
298
+ - **env**: `[in] napi_env` environment under which the function is invoked.
299
+ - **info**: `[in] napi_callback_info` callback data.
300
+ - **fcn**: `[in] stdlib_complex64_t (*fcn)( stdlib_complex64_t, stdlib_complex64_t )` binary function.
301
+
302
+ ```c
303
+ void stdlib_math_base_napi_cc_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t, stdlib_complex64_t ) );
205
304
  ```
206
305
 
207
306
  #### STDLIB_MATH_BASE_NAPI_MODULE_DD_D( fcn )
208
307
 
209
- Macro for registering an N-API module exporting an interface for invoking a binary function accepting and returning double-precision floating-point numbers.
308
+ Macro for registering a Node-API module exporting an interface for invoking a binary function accepting and returning double-precision floating-point numbers.
210
309
 
211
310
  ```c
212
311
  static double add( const double x, const double y ) {
@@ -215,7 +314,7 @@ static double add( const double x, const double y ) {
215
314
 
216
315
  // ...
217
316
 
218
- // Register an N-API module:
317
+ // Register a Node-API module:
219
318
  STDLIB_MATH_BASE_NAPI_MODULE_DD_D( add );
220
319
  ```
221
320
 
@@ -223,11 +322,11 @@ The macro expects the following arguments:
223
322
 
224
323
  - **fcn**: `double (*fcn)( double, double )` binary function.
225
324
 
226
- When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring N-API module registration.
325
+ When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.
227
326
 
228
327
  #### STDLIB_MATH_BASE_NAPI_MODULE_FF_F( fcn )
229
328
 
230
- Macro for registering an N-API module exporting an interface for invoking a binary function accepting and returning single-precision floating-point numbers.
329
+ Macro for registering a Node-API module exporting an interface for invoking a binary function accepting and returning single-precision floating-point numbers.
231
330
 
232
331
  ```c
233
332
  static float addf( const float x, const float y ) {
@@ -236,7 +335,7 @@ static float addf( const float x, const float y ) {
236
335
 
237
336
  // ...
238
337
 
239
- // Register an N-API module:
338
+ // Register a Node-API module:
240
339
  STDLIB_MATH_BASE_NAPI_MODULE_FF_F( addf );
241
340
  ```
242
341
 
@@ -244,7 +343,81 @@ The macro expects the following arguments:
244
343
 
245
344
  - **fcn**: `float (*fcn)( float, float )` binary function.
246
345
 
247
- When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring N-API module registration.
346
+ When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.
347
+
348
+ #### STDLIB_MATH_BASE_NAPI_MODULE_ZZ_Z( fcn )
349
+
350
+ Macro for registering a Node-API module exporting an interface for invoking a binary function accepting and returning double-precision complex floating-point numbers.
351
+
352
+ ```c
353
+ #include "stdlib/complex/float64.h"
354
+ #include "stdlib/complex/reim.h"
355
+
356
+ static stdlib_complex128_t add( const stdlib_complex128_t x, const stdlib_complex128_t y ) {
357
+ double xre;
358
+ double xim;
359
+ double yre;
360
+ double yim;
361
+ double re;
362
+ double im;
363
+
364
+ stdlib_reim( x, &xre, &xim );
365
+ stdlib_reim( y, &yre, &yim );
366
+
367
+ re = xre + yre;
368
+ im = xim + yim;
369
+
370
+ return stdlib_complex128( re, im );
371
+ }
372
+
373
+ // ...
374
+
375
+ // Register a Node-API module:
376
+ STDLIB_MATH_BASE_NAPI_MODULE_ZZ_Z( add );
377
+ ```
378
+
379
+ The macro expects the following arguments:
380
+
381
+ - **fcn**: `stdlib_complex128_t (*fcn)( stdlib_complex128_t, stdlib_complex128_t )` binary function.
382
+
383
+ When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.
384
+
385
+ #### STDLIB_MATH_BASE_NAPI_MODULE_CC_C( fcn )
386
+
387
+ Macro for registering a Node-API module exporting an interface for invoking a binary function accepting and returning single-precision complex floating-point numbers.
388
+
389
+ ```c
390
+ #include "stdlib/complex/float32.h"
391
+ #include "stdlib/complex/reimf.h"
392
+
393
+ static stdlib_complex64_t add( const stdlib_complex64_t x, const stdlib_complex64_t y ) {
394
+ float xre;
395
+ float xim;
396
+ float yre;
397
+ float yim;
398
+ float re;
399
+ float im;
400
+
401
+ stdlib_reimf( x, &xre, &xim );
402
+ stdlib_reimf( y, &yre, &yim );
403
+
404
+ re = xre + yre;
405
+ im = xim + yim;
406
+
407
+ return stdlib_complex64( re, im );
408
+ }
409
+
410
+ // ...
411
+
412
+ // Register a Node-API module:
413
+ STDLIB_MATH_BASE_NAPI_MODULE_CC_C( add );
414
+ ```
415
+
416
+ The macro expects the following arguments:
417
+
418
+ - **fcn**: `stdlib_complex64_t (*fcn)( stdlib_complex64_t, stdlib_complex64_t )` binary function.
419
+
420
+ When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration.
248
421
 
249
422
  </section>
250
423
 
@@ -285,6 +458,14 @@ When used, this macro should be used **instead of** `NAPI_MODULE`. The macro inc
285
458
 
286
459
  <!-- /.references -->
287
460
 
461
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
462
+
463
+ <section class="related">
464
+
465
+ </section>
466
+
467
+ <!-- /.related -->
468
+
288
469
  <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
289
470
 
290
471
 
@@ -298,6 +479,10 @@ This package is part of [stdlib][stdlib], a standard library for JavaScript and
298
479
 
299
480
  For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
300
481
 
482
+ #### Community
483
+
484
+ [![Chat][chat-image]][chat-url]
485
+
301
486
  ---
302
487
 
303
488
  ## License
@@ -307,7 +492,7 @@ See [LICENSE][stdlib-license].
307
492
 
308
493
  ## Copyright
309
494
 
310
- Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
495
+ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
311
496
 
312
497
  </section>
313
498
 
@@ -326,9 +511,23 @@ Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
326
511
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-napi-binary/main.svg
327
512
  [coverage-url]: https://codecov.io/github/stdlib-js/math-base-napi-binary?branch=main
328
513
 
329
- [dependencies-image]: https://img.shields.io/david/stdlib-js/math-base-napi-binary
514
+ <!--
515
+
516
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/math-base-napi-binary.svg
330
517
  [dependencies-url]: https://david-dm.org/stdlib-js/math-base-napi-binary/main
331
518
 
519
+ -->
520
+
521
+ [umd]: https://github.com/umdjs/umd
522
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
523
+
524
+ [deno-url]: https://github.com/stdlib-js/math-base-napi-binary/tree/deno
525
+ [umd-url]: https://github.com/stdlib-js/math-base-napi-binary/tree/umd
526
+ [esm-url]: https://github.com/stdlib-js/math-base-napi-binary/tree/esm
527
+
528
+ [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
529
+ [chat-url]: https://gitter.im/stdlib-js/stdlib/
530
+
332
531
  [stdlib]: https://github.com/stdlib-js/stdlib
333
532
 
334
533
  [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
@@ -19,11 +19,13 @@
19
19
  #ifndef STDLIB_MATH_BASE_NAPI_BINARY_H
20
20
  #define STDLIB_MATH_BASE_NAPI_BINARY_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
 
25
27
  /**
26
- * Macro for registering an N-API module exporting an interface invoking a binary function accepting and returning double-precision floating-point numbers.
28
+ * Macro for registering a Node-API module exporting an interface invoking a binary function accepting and returning double-precision floating-point numbers.
27
29
  *
28
30
  * @param fcn binary function
29
31
  *
@@ -34,7 +36,7 @@
34
36
  *
35
37
  * // ...
36
38
  *
37
- * // Register an N-API module:
39
+ * // Register a Node-API module:
38
40
  * STDLIB_MATH_BASE_NAPI_MODULE_DD_D( add );
39
41
  */
40
42
  #define STDLIB_MATH_BASE_NAPI_MODULE_DD_D( fcn ) \
@@ -63,7 +65,7 @@
63
65
  NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_dd_d_init )
64
66
 
65
67
  /**
66
- * Macro for registering an N-API module exporting an interface invoking a binary function accepting and returning single-precision floating-point numbers.
68
+ * Macro for registering a Node-API module exporting an interface invoking a binary function accepting and returning single-precision floating-point numbers.
67
69
  *
68
70
  * @param fcn binary function
69
71
  *
@@ -74,7 +76,7 @@
74
76
  *
75
77
  * // ...
76
78
  *
77
- * // Register an N-API module:
79
+ * // Register a Node-API module:
78
80
  * STDLIB_MATH_BASE_NAPI_MODULE_FF_F( addf );
79
81
  */
80
82
  #define STDLIB_MATH_BASE_NAPI_MODULE_FF_F( fcn ) \
@@ -102,6 +104,118 @@
102
104
  }; \
103
105
  NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_ff_f_init )
104
106
 
107
+ /**
108
+ * Macro for registering a Node-API module exporting an interface invoking a binary function accepting and returning double-precision complex floating-point numbers.
109
+ *
110
+ * @param fcn binary function
111
+ *
112
+ * @example
113
+ * #include "stdlib/complex/float64.h"
114
+ * #include "stdlib/complex/reim.h"
115
+ *
116
+ * static stdlib_complex128_t add( const stdlib_complex128_t x, const stdlib_complex128_t y ) {
117
+ * double xre;
118
+ * double xim;
119
+ * double yre;
120
+ * double yim;
121
+ * double re;
122
+ * double im;
123
+ *
124
+ * stdlib_reim( x, &xre, &xim );
125
+ * stdlib_reim( y, &yre, &yim );
126
+ *
127
+ * re = xre + yre;
128
+ * im = xim + yim;
129
+ *
130
+ * return stdlib_complex128( re, im );
131
+ * }
132
+ *
133
+ * // ...
134
+ *
135
+ * // Register a Node-API module:
136
+ * STDLIB_MATH_BASE_NAPI_MODULE_ZZ_Z( add );
137
+ */
138
+ #define STDLIB_MATH_BASE_NAPI_MODULE_ZZ_Z( fcn ) \
139
+ static napi_value stdlib_math_base_napi_zz_z_wrapper( \
140
+ napi_env env, \
141
+ napi_callback_info info \
142
+ ) { \
143
+ return stdlib_math_base_napi_zz_z( env, info, fcn ); \
144
+ }; \
145
+ static napi_value stdlib_math_base_napi_zz_z_init( \
146
+ napi_env env, \
147
+ napi_value exports \
148
+ ) { \
149
+ napi_value fcn; \
150
+ napi_status status = napi_create_function( \
151
+ env, \
152
+ "exports", \
153
+ NAPI_AUTO_LENGTH, \
154
+ stdlib_math_base_napi_zz_z_wrapper, \
155
+ NULL, \
156
+ &fcn \
157
+ ); \
158
+ assert( status == napi_ok ); \
159
+ return fcn; \
160
+ }; \
161
+ NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_zz_z_init )
162
+
163
+ /**
164
+ * Macro for registering a Node-API module exporting an interface invoking a binary function accepting and returning single-precision complex floating-point numbers.
165
+ *
166
+ * @param fcn binary function
167
+ *
168
+ * @example
169
+ * #include "stdlib/complex/float32.h"
170
+ * #include "stdlib/complex/reimf.h"
171
+ *
172
+ * static stdlib_complex64_t add( const stdlib_complex64_t x, const stdlib_complex64_t y ) {
173
+ * float xre;
174
+ * float xim;
175
+ * float yre;
176
+ * float yim;
177
+ * float re;
178
+ * float im;
179
+ *
180
+ * stdlib_reimf( x, &xre, &xim );
181
+ * stdlib_reimf( y, &yre, &yim );
182
+ *
183
+ * re = xre + yre;
184
+ * im = xim + yim;
185
+ *
186
+ * return stdlib_complex64( re, im );
187
+ * }
188
+ *
189
+ * // ...
190
+ *
191
+ * // Register a Node-API module:
192
+ * STDLIB_MATH_BASE_NAPI_MODULE_CC_C( add );
193
+ */
194
+ #define STDLIB_MATH_BASE_NAPI_MODULE_CC_C( fcn ) \
195
+ static napi_value stdlib_math_base_napi_cc_c_wrapper( \
196
+ napi_env env, \
197
+ napi_callback_info info \
198
+ ) { \
199
+ return stdlib_math_base_napi_cc_c( env, info, fcn ); \
200
+ }; \
201
+ static napi_value stdlib_math_base_napi_cc_c_init( \
202
+ napi_env env, \
203
+ napi_value exports \
204
+ ) { \
205
+ napi_value fcn; \
206
+ napi_status status = napi_create_function( \
207
+ env, \
208
+ "exports", \
209
+ NAPI_AUTO_LENGTH, \
210
+ stdlib_math_base_napi_cc_c_wrapper, \
211
+ NULL, \
212
+ &fcn \
213
+ ); \
214
+ assert( status == napi_ok ); \
215
+ return fcn; \
216
+ }; \
217
+ NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_cc_c_init )
218
+
105
219
  /*
106
220
  * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
107
221
  */
@@ -119,6 +233,16 @@ napi_value stdlib_math_base_napi_dd_d( napi_env env, napi_callback_info info, do
119
233
  */
120
234
  napi_value stdlib_math_base_napi_ff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float ) );
121
235
 
236
+ /**
237
+ * Invokes a binary function accepting and returning double-precision complex floating-point numbers.
238
+ */
239
+ napi_value stdlib_math_base_napi_zz_z( napi_env env, napi_callback_info info, stdlib_complex128_t (*fcn)( stdlib_complex128_t, stdlib_complex128_t ) );
240
+
241
+ /**
242
+ * Invokes a binary function accepting and returning single-precision complex floating-point numbers.
243
+ */
244
+ napi_value stdlib_math_base_napi_cc_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t, stdlib_complex64_t ) );
245
+
122
246
  #ifdef __cplusplus
123
247
  }
124
248
  #endif
package/manifest.json CHANGED
@@ -32,7 +32,12 @@
32
32
  ],
33
33
  "libraries": [],
34
34
  "libpath": [],
35
- "dependencies": []
35
+ "dependencies": [
36
+ "@stdlib/complex-float32",
37
+ "@stdlib/complex-float64",
38
+ "@stdlib/complex-reim",
39
+ "@stdlib/complex-reimf"
40
+ ]
36
41
  }
37
42
  ]
38
43
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stdlib/math-base-napi-binary",
3
- "version": "0.0.4",
4
- "description": "C APIs for registering an N-API module exporting an interface for invoking a binary numerical function.",
3
+ "version": "0.0.8",
4
+ "description": "C APIs for registering a Node-API module exporting an interface for invoking a binary numerical function.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
7
7
  "name": "The Stdlib Authors",
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "main": "./lib",
17
17
  "browser": "./lib/browser.js",
18
- "gypfile": true,
18
+ "gypfile": false,
19
19
  "directories": {
20
20
  "benchmark": "./benchmark",
21
21
  "doc": "./docs",
@@ -32,7 +32,7 @@
32
32
  "examples": "make examples",
33
33
  "benchmark": "make benchmark"
34
34
  },
35
- "homepage": "https://github.com/stdlib-js/stdlib",
35
+ "homepage": "https://stdlib.io",
36
36
  "repository": {
37
37
  "type": "git",
38
38
  "url": "git://github.com/stdlib-js/math-base-napi-binary.git"
@@ -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": {
@@ -74,6 +78,7 @@
74
78
  "math",
75
79
  "napi",
76
80
  "n-api",
81
+ "node-api",
77
82
  "addon",
78
83
  "binary",
79
84
  "map",
package/src/main.c CHANGED
@@ -17,9 +17,14 @@
17
17
  */
18
18
 
19
19
  #include "stdlib/math/base/napi/binary.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 binary function accepting and returning double-precision floating-point numbers.
@@ -34,7 +39,7 @@
34
39
  * @param env environment under which the function is invoked
35
40
  * @param info callback data
36
41
  * @param fcn binary function
37
- * @return function return value as an N-API double-precision floating-point number
42
+ * @return function return value as a Node-API double-precision floating-point number
38
43
  */
39
44
  napi_value stdlib_math_base_napi_dd_d( napi_env env, napi_callback_info info, double (*fcn)( double, double ) ) {
40
45
  napi_status status;
@@ -96,7 +101,7 @@ napi_value stdlib_math_base_napi_dd_d( napi_env env, napi_callback_info info, do
96
101
  * @param env environment under which the function is invoked
97
102
  * @param info callback data
98
103
  * @param fcn binary function
99
- * @return function return value as an N-API double-precision floating-point number
104
+ * @return function return value as a Node-API double-precision floating-point number
100
105
  */
101
106
  napi_value stdlib_math_base_napi_ff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float ) ) {
102
107
  napi_status status;
@@ -144,3 +149,315 @@ napi_value stdlib_math_base_napi_ff_f( napi_env env, napi_callback_info info, fl
144
149
 
145
150
  return v;
146
151
  }
152
+
153
+ /**
154
+ * Invokes a binary function accepting and returning double-precision complex floating-point numbers.
155
+ *
156
+ * ## Notes
157
+ *
158
+ * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
159
+ *
160
+ * - `x`: input value.
161
+ * - `y`: input value.
162
+ *
163
+ * @param env environment under which the function is invoked
164
+ * @param info callback data
165
+ * @param fcn binary function
166
+ * @return function return value as a Node-API complex-like object
167
+ */
168
+ napi_value stdlib_math_base_napi_zz_z( napi_env env, napi_callback_info info, stdlib_complex128_t (*fcn)( stdlib_complex128_t, stdlib_complex128_t ) ) {
169
+ napi_status status;
170
+
171
+ size_t argc = 2;
172
+ napi_value argv[ 2 ];
173
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
174
+ assert( status == napi_ok );
175
+
176
+ if ( argc < 2 ) {
177
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide two complex numbers." );
178
+ assert( status == napi_ok );
179
+ return NULL;
180
+ }
181
+
182
+ bool hprop;
183
+ status = napi_has_named_property( env, argv[ 0 ], "re", &hprop );
184
+ assert( status == napi_ok );
185
+ if ( !hprop ) {
186
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component." );
187
+ assert( status == napi_ok );
188
+ return NULL;
189
+ }
190
+
191
+ napi_value xre;
192
+ status = napi_get_named_property( env, argv[ 0 ], "re", &xre );
193
+ assert( status == napi_ok );
194
+
195
+ napi_valuetype xretype;
196
+ status = napi_typeof( env, xre, &xretype );
197
+ assert( status == napi_ok );
198
+ if ( xretype != napi_number ) {
199
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component which is a number." );
200
+ assert( status == napi_ok );
201
+ return NULL;
202
+ }
203
+
204
+ status = napi_has_named_property( env, argv[ 0 ], "im", &hprop );
205
+ assert( status == napi_ok );
206
+ if ( !hprop ) {
207
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component." );
208
+ assert( status == napi_ok );
209
+ return NULL;
210
+ }
211
+
212
+ napi_value xim;
213
+ status = napi_get_named_property( env, argv[ 0 ], "im", &xim );
214
+ assert( status == napi_ok );
215
+
216
+ napi_valuetype ximtype;
217
+ status = napi_typeof( env, xim, &ximtype );
218
+ assert( status == napi_ok );
219
+ if ( ximtype != napi_number ) {
220
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component which a number." );
221
+ assert( status == napi_ok );
222
+ return NULL;
223
+ }
224
+
225
+ status = napi_has_named_property( env, argv[ 1 ], "re", &hprop );
226
+ assert( status == napi_ok );
227
+ if ( !hprop ) {
228
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have a real component." );
229
+ assert( status == napi_ok );
230
+ return NULL;
231
+ }
232
+
233
+ napi_value yre;
234
+ status = napi_get_named_property( env, argv[ 1 ], "re", &yre );
235
+ assert( status == napi_ok );
236
+
237
+ napi_valuetype yretype;
238
+ status = napi_typeof( env, yre, &yretype );
239
+ assert( status == napi_ok );
240
+ if ( yretype != napi_number ) {
241
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have a real component which is a number." );
242
+ assert( status == napi_ok );
243
+ return NULL;
244
+ }
245
+
246
+ status = napi_has_named_property( env, argv[ 1 ], "im", &hprop );
247
+ assert( status == napi_ok );
248
+ if ( !hprop ) {
249
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have an imaginary component." );
250
+ assert( status == napi_ok );
251
+ return NULL;
252
+ }
253
+
254
+ napi_value yim;
255
+ status = napi_get_named_property( env, argv[ 1 ], "im", &yim );
256
+ assert( status == napi_ok );
257
+
258
+ napi_valuetype yimtype;
259
+ status = napi_typeof( env, yim, &yimtype );
260
+ assert( status == napi_ok );
261
+ if ( yimtype != napi_number ) {
262
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have an imaginary component which a number." );
263
+ assert( status == napi_ok );
264
+ return NULL;
265
+ }
266
+
267
+ double re0;
268
+ status = napi_get_value_double( env, xre, &re0 );
269
+ assert( status == napi_ok );
270
+
271
+ double im0;
272
+ status = napi_get_value_double( env, xim, &im0 );
273
+ assert( status == napi_ok );
274
+
275
+ double re1;
276
+ status = napi_get_value_double( env, yre, &re1 );
277
+ assert( status == napi_ok );
278
+
279
+ double im1;
280
+ status = napi_get_value_double( env, yim, &im1 );
281
+ assert( status == napi_ok );
282
+
283
+ stdlib_complex128_t v = fcn( stdlib_complex128( re0, im0 ), stdlib_complex128( re1, im1 ) );
284
+ double re;
285
+ double im;
286
+ stdlib_reim( v, &re, &im );
287
+
288
+ napi_value obj;
289
+ status = napi_create_object( env, &obj );
290
+ assert( status == napi_ok );
291
+
292
+ napi_value vre;
293
+ status = napi_create_double( env, re, &vre );
294
+ assert( status == napi_ok );
295
+
296
+ status = napi_set_named_property( env, obj, "re", vre );
297
+ assert( status == napi_ok );
298
+
299
+ napi_value vim;
300
+ status = napi_create_double( env, im, &vim );
301
+ assert( status == napi_ok );
302
+
303
+ status = napi_set_named_property( env, obj, "im", vim );
304
+ assert( status == napi_ok );
305
+
306
+ return obj;
307
+ }
308
+
309
+ /**
310
+ * Invokes a binary function accepting and returning single-precision complex floating-point numbers.
311
+ *
312
+ * ## Notes
313
+ *
314
+ * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
315
+ *
316
+ * - `x`: input value.
317
+ * - `y`: input value.
318
+ *
319
+ * @param env environment under which the function is invoked
320
+ * @param info callback data
321
+ * @param fcn binary function
322
+ * @return function return value as a Node-API complex-like object
323
+ */
324
+ napi_value stdlib_math_base_napi_cc_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t, stdlib_complex64_t ) ) {
325
+ napi_status status;
326
+
327
+ size_t argc = 2;
328
+ napi_value argv[ 2 ];
329
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
330
+ assert( status == napi_ok );
331
+
332
+ if ( argc < 2 ) {
333
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide two complex numbers." );
334
+ assert( status == napi_ok );
335
+ return NULL;
336
+ }
337
+
338
+ bool hprop;
339
+ status = napi_has_named_property( env, argv[ 0 ], "re", &hprop );
340
+ assert( status == napi_ok );
341
+ if ( !hprop ) {
342
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component." );
343
+ assert( status == napi_ok );
344
+ return NULL;
345
+ }
346
+
347
+ napi_value xre;
348
+ status = napi_get_named_property( env, argv[ 0 ], "re", &xre );
349
+ assert( status == napi_ok );
350
+
351
+ napi_valuetype xretype;
352
+ status = napi_typeof( env, xre, &xretype );
353
+ assert( status == napi_ok );
354
+ if ( xretype != napi_number ) {
355
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component which is a number." );
356
+ assert( status == napi_ok );
357
+ return NULL;
358
+ }
359
+
360
+ status = napi_has_named_property( env, argv[ 0 ], "im", &hprop );
361
+ assert( status == napi_ok );
362
+ if ( !hprop ) {
363
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component." );
364
+ assert( status == napi_ok );
365
+ return NULL;
366
+ }
367
+
368
+ napi_value xim;
369
+ status = napi_get_named_property( env, argv[ 0 ], "im", &xim );
370
+ assert( status == napi_ok );
371
+
372
+ napi_valuetype ximtype;
373
+ status = napi_typeof( env, xim, &ximtype );
374
+ assert( status == napi_ok );
375
+ if ( ximtype != napi_number ) {
376
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component which a number." );
377
+ assert( status == napi_ok );
378
+ return NULL;
379
+ }
380
+
381
+ status = napi_has_named_property( env, argv[ 1 ], "re", &hprop );
382
+ assert( status == napi_ok );
383
+ if ( !hprop ) {
384
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have a real component." );
385
+ assert( status == napi_ok );
386
+ return NULL;
387
+ }
388
+
389
+ napi_value yre;
390
+ status = napi_get_named_property( env, argv[ 1 ], "re", &yre );
391
+ assert( status == napi_ok );
392
+
393
+ napi_valuetype yretype;
394
+ status = napi_typeof( env, yre, &yretype );
395
+ assert( status == napi_ok );
396
+ if ( yretype != napi_number ) {
397
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have a real component which is a number." );
398
+ assert( status == napi_ok );
399
+ return NULL;
400
+ }
401
+
402
+ status = napi_has_named_property( env, argv[ 1 ], "im", &hprop );
403
+ assert( status == napi_ok );
404
+ if ( !hprop ) {
405
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have an imaginary component." );
406
+ assert( status == napi_ok );
407
+ return NULL;
408
+ }
409
+
410
+ napi_value yim;
411
+ status = napi_get_named_property( env, argv[ 1 ], "im", &yim );
412
+ assert( status == napi_ok );
413
+
414
+ napi_valuetype yimtype;
415
+ status = napi_typeof( env, yim, &yimtype );
416
+ assert( status == napi_ok );
417
+ if ( yimtype != napi_number ) {
418
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have an imaginary component which a number." );
419
+ assert( status == napi_ok );
420
+ return NULL;
421
+ }
422
+
423
+ double re0;
424
+ status = napi_get_value_double( env, xre, &re0 );
425
+ assert( status == napi_ok );
426
+
427
+ double im0;
428
+ status = napi_get_value_double( env, xim, &im0 );
429
+ assert( status == napi_ok );
430
+
431
+ double re1;
432
+ status = napi_get_value_double( env, yre, &re1 );
433
+ assert( status == napi_ok );
434
+
435
+ double im1;
436
+ status = napi_get_value_double( env, yim, &im1 );
437
+ assert( status == napi_ok );
438
+
439
+ stdlib_complex64_t v = fcn( stdlib_complex64( (float)re0, (float)im0 ), stdlib_complex64( (float)re1, (float)im1 ) );
440
+ float re;
441
+ float im;
442
+ stdlib_reimf( v, &re, &im );
443
+
444
+ napi_value obj;
445
+ status = napi_create_object( env, &obj );
446
+ assert( status == napi_ok );
447
+
448
+ napi_value vre;
449
+ status = napi_create_double( env, (double)re, &vre );
450
+ assert( status == napi_ok );
451
+
452
+ status = napi_set_named_property( env, obj, "re", vre );
453
+ assert( status == napi_ok );
454
+
455
+ napi_value vim;
456
+ status = napi_create_double( env, (double)im, &vim );
457
+ assert( status == napi_ok );
458
+
459
+ status = napi_set_named_property( env, obj, "im", vim );
460
+ assert( status == napi_ok );
461
+
462
+ return obj;
463
+ }
package/CHANGELOG.md DELETED
@@ -1,5 +0,0 @@
1
- # CHANGELOG
2
-
3
- > Package changelog.
4
-
5
- See [GitHub Releases](https://github.com/stdlib-js/math-base-napi-binary/releases) for the changelog.
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
- }