@stdlib/math-base-napi-binary 0.2.1 → 0.3.1

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.
Files changed (51) hide show
  1. package/NOTICE +1 -1
  2. package/README.md +1155 -252
  3. package/include/stdlib/math/base/napi/binary/bb_b.h +84 -0
  4. package/include/stdlib/math/base/napi/binary/cc_c.h +98 -0
  5. package/include/stdlib/math/base/napi/binary/cf_c.h +89 -0
  6. package/include/stdlib/math/base/napi/binary/ci_c.h +91 -0
  7. package/include/stdlib/math/base/napi/binary/dd_d.h +81 -0
  8. package/include/stdlib/math/base/napi/binary/di_d.h +84 -0
  9. package/include/stdlib/math/base/napi/binary/dz_z.h +89 -0
  10. package/include/stdlib/math/base/napi/binary/fc_c.h +89 -0
  11. package/include/stdlib/math/base/napi/binary/ff_f.h +81 -0
  12. package/include/stdlib/math/base/napi/binary/fi_f.h +84 -0
  13. package/include/stdlib/math/base/napi/binary/id_d.h +84 -0
  14. package/include/stdlib/math/base/napi/binary/ii_d.h +84 -0
  15. package/include/stdlib/math/base/napi/binary/ii_f.h +84 -0
  16. package/include/stdlib/math/base/napi/binary/ii_i.h +84 -0
  17. package/include/stdlib/math/base/napi/binary/kk_k.h +84 -0
  18. package/include/stdlib/math/base/napi/binary/ll_d.h +84 -0
  19. package/include/stdlib/math/base/napi/binary/ss_s.h +84 -0
  20. package/include/stdlib/math/base/napi/binary/tt_t.h +84 -0
  21. package/include/stdlib/math/base/napi/binary/uu_u.h +84 -0
  22. package/include/stdlib/math/base/napi/binary/zd_z.h +89 -0
  23. package/include/stdlib/math/base/napi/binary/zi_z.h +91 -0
  24. package/include/stdlib/math/base/napi/binary/zz_z.h +98 -0
  25. package/include/stdlib/math/base/napi/binary.h +23 -531
  26. package/manifest.json +60 -40
  27. package/package.json +6 -6
  28. package/src/bb_b.c +84 -0
  29. package/src/cc_c.c +179 -0
  30. package/src/cf_c.c +143 -0
  31. package/src/ci_c.c +143 -0
  32. package/src/dd_d.c +83 -0
  33. package/src/di_d.c +84 -0
  34. package/src/dz_z.c +142 -0
  35. package/src/fc_c.c +142 -0
  36. package/src/ff_f.c +83 -0
  37. package/src/fi_f.c +84 -0
  38. package/src/id_d.c +84 -0
  39. package/src/ii_d.c +84 -0
  40. package/src/ii_f.c +84 -0
  41. package/src/ii_i.c +84 -0
  42. package/src/kk_k.c +84 -0
  43. package/src/ll_d.c +84 -0
  44. package/src/ss_s.c +84 -0
  45. package/src/tt_t.c +84 -0
  46. package/src/uu_u.c +84 -0
  47. package/src/zd_z.c +142 -0
  48. package/src/zi_z.c +143 -0
  49. package/src/zz_z.c +179 -0
  50. package/include.gypi +0 -53
  51. package/src/main.c +0 -1063
package/src/main.c DELETED
@@ -1,1063 +0,0 @@
1
- /**
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2020 The Stdlib Authors.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
-
19
- #include "stdlib/math/base/napi/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"
24
- #include <node_api.h>
25
- #include <stdint.h>
26
- #include <assert.h>
27
- #include <stdbool.h>
28
-
29
- /**
30
- * Invokes a binary function accepting and returning double-precision floating-point numbers.
31
- *
32
- * ## Notes
33
- *
34
- * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
35
- *
36
- * - `x`: input value.
37
- * - `y`: input value.
38
- *
39
- * @param env environment under which the function is invoked
40
- * @param info callback data
41
- * @param fcn binary function
42
- * @return function return value as a Node-API double-precision floating-point number
43
- */
44
- napi_value stdlib_math_base_napi_dd_d( napi_env env, napi_callback_info info, double (*fcn)( double, double ) ) {
45
- napi_status status;
46
-
47
- size_t argc = 2;
48
- napi_value argv[ 2 ];
49
- status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
50
- assert( status == napi_ok );
51
-
52
- if ( argc < 2 ) {
53
- status = napi_throw_error( env, NULL, "invalid invocation. Must provide two numbers." );
54
- assert( status == napi_ok );
55
- return NULL;
56
- }
57
-
58
- napi_valuetype vtype0;
59
- status = napi_typeof( env, argv[ 0 ], &vtype0 );
60
- assert( status == napi_ok );
61
- if ( vtype0 != napi_number ) {
62
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
63
- assert( status == napi_ok );
64
- return NULL;
65
- }
66
-
67
- napi_valuetype vtype1;
68
- status = napi_typeof( env, argv[ 1 ], &vtype1 );
69
- assert( status == napi_ok );
70
- if ( vtype1 != napi_number ) {
71
- status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
72
- assert( status == napi_ok );
73
- return NULL;
74
- }
75
-
76
- double x;
77
- status = napi_get_value_double( env, argv[ 0 ], &x );
78
- assert( status == napi_ok );
79
-
80
- double y;
81
- status = napi_get_value_double( env, argv[ 1 ], &y );
82
- assert( status == napi_ok );
83
-
84
- napi_value v;
85
- status = napi_create_double( env, fcn( x, y ), &v );
86
- assert( status == napi_ok );
87
-
88
- return v;
89
- }
90
-
91
- /**
92
- * Invokes a binary function accepting and returning single-precision floating-point numbers.
93
- *
94
- * ## Notes
95
- *
96
- * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
97
- *
98
- * - `x`: input value.
99
- * - `y`: input value.
100
- *
101
- * @param env environment under which the function is invoked
102
- * @param info callback data
103
- * @param fcn binary function
104
- * @return function return value as a Node-API double-precision floating-point number
105
- */
106
- napi_value stdlib_math_base_napi_ff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float ) ) {
107
- napi_status status;
108
-
109
- size_t argc = 2;
110
- napi_value argv[ 2 ];
111
- status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
112
- assert( status == napi_ok );
113
-
114
- if ( argc < 2 ) {
115
- status = napi_throw_error( env, NULL, "invalid invocation. Must provide two numbers." );
116
- assert( status == napi_ok );
117
- return NULL;
118
- }
119
-
120
- napi_valuetype vtype0;
121
- status = napi_typeof( env, argv[ 0 ], &vtype0 );
122
- assert( status == napi_ok );
123
- if ( vtype0 != napi_number ) {
124
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
125
- assert( status == napi_ok );
126
- return NULL;
127
- }
128
-
129
- napi_valuetype vtype1;
130
- status = napi_typeof( env, argv[ 1 ], &vtype1 );
131
- assert( status == napi_ok );
132
- if ( vtype1 != napi_number ) {
133
- status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
134
- assert( status == napi_ok );
135
- return NULL;
136
- }
137
-
138
- double x;
139
- status = napi_get_value_double( env, argv[ 0 ], &x );
140
- assert( status == napi_ok );
141
-
142
- double y;
143
- status = napi_get_value_double( env, argv[ 1 ], &y );
144
- assert( status == napi_ok );
145
-
146
- napi_value v;
147
- status = napi_create_double( env, (double)fcn( (float)x, (float)y ), &v );
148
- assert( status == napi_ok );
149
-
150
- return v;
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
- }
464
-
465
- /**
466
- * Invokes a binary function accepting a double-precision floating-point number and a signed 32-bit integer and returning a double-precision floating-point number.
467
- *
468
- * ## Notes
469
- *
470
- * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
471
- *
472
- * - `x`: input value.
473
- * - `y`: input value.
474
- *
475
- * @param env environment under which the function is invoked
476
- * @param info callback data
477
- * @param fcn binary function
478
- * @return function return value as a Node-API double-precision floating-point number
479
- */
480
- napi_value stdlib_math_base_napi_di_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t ) ) {
481
- napi_status status;
482
-
483
- size_t argc = 2;
484
- napi_value argv[ 2 ];
485
- status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
486
- assert( status == napi_ok );
487
-
488
- if ( argc < 2 ) {
489
- status = napi_throw_error( env, NULL, "invalid invocation. Must provide two numbers." );
490
- assert( status == napi_ok );
491
- return NULL;
492
- }
493
-
494
- napi_valuetype vtype0;
495
- status = napi_typeof( env, argv[ 0 ], &vtype0 );
496
- assert( status == napi_ok );
497
- if ( vtype0 != napi_number ) {
498
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
499
- assert( status == napi_ok );
500
- return NULL;
501
- }
502
-
503
- napi_valuetype vtype1;
504
- status = napi_typeof( env, argv[ 1 ], &vtype1 );
505
- assert( status == napi_ok );
506
- if ( vtype1 != napi_number ) {
507
- status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
508
- assert( status == napi_ok );
509
- return NULL;
510
- }
511
-
512
- double x;
513
- status = napi_get_value_double( env, argv[ 0 ], &x );
514
- assert( status == napi_ok );
515
-
516
- int32_t y;
517
- status = napi_get_value_int32( env, argv[ 1 ], &y );
518
- assert( status == napi_ok );
519
-
520
- napi_value v;
521
- status = napi_create_double( env, fcn( x, y ), &v );
522
- assert( status == napi_ok );
523
-
524
- return v;
525
- }
526
-
527
- /**
528
- * Invokes a binary function accepting a single-precision floating-point number and a signed 32-bit integer and returning a single-precision floating-point number.
529
- *
530
- * ## Notes
531
- *
532
- * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
533
- *
534
- * - `x`: input value.
535
- * - `y`: input value.
536
- *
537
- * @param env environment under which the function is invoked
538
- * @param info callback data
539
- * @param fcn binary function
540
- * @return function return value as a Node-API double-precision floating-point number
541
- */
542
- napi_value stdlib_math_base_napi_fi_f( napi_env env, napi_callback_info info, float (*fcn)( float, int32_t ) ) {
543
- napi_status status;
544
-
545
- size_t argc = 2;
546
- napi_value argv[ 2 ];
547
- status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
548
- assert( status == napi_ok );
549
-
550
- if ( argc < 2 ) {
551
- status = napi_throw_error( env, NULL, "invalid invocation. Must provide two numbers." );
552
- assert( status == napi_ok );
553
- return NULL;
554
- }
555
-
556
- napi_valuetype vtype0;
557
- status = napi_typeof( env, argv[ 0 ], &vtype0 );
558
- assert( status == napi_ok );
559
- if ( vtype0 != napi_number ) {
560
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
561
- assert( status == napi_ok );
562
- return NULL;
563
- }
564
-
565
- napi_valuetype vtype1;
566
- status = napi_typeof( env, argv[ 1 ], &vtype1 );
567
- assert( status == napi_ok );
568
- if ( vtype1 != napi_number ) {
569
- status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
570
- assert( status == napi_ok );
571
- return NULL;
572
- }
573
-
574
- double x;
575
- status = napi_get_value_double( env, argv[ 0 ], &x );
576
- assert( status == napi_ok );
577
-
578
- int32_t y;
579
- status = napi_get_value_int32( env, argv[ 1 ], &y );
580
- assert( status == napi_ok );
581
-
582
- napi_value v;
583
- status = napi_create_double( env, (double)fcn( (float)x, y ), &v );
584
- assert( status == napi_ok );
585
-
586
- return v;
587
- }
588
-
589
- /**
590
- * Invokes a binary function accepting a double-precision complex floating-point number and a signed 32-bit integer and returning a double-precision complex floating-point number.
591
- *
592
- * ## Notes
593
- *
594
- * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
595
- *
596
- * - `x`: input value.
597
- * - `y`: input value.
598
- *
599
- * @param env environment under which the function is invoked
600
- * @param info callback data
601
- * @param fcn binary function
602
- * @return function return value as a Node-API complex-like object
603
- */
604
- napi_value stdlib_math_base_napi_zi_z( napi_env env, napi_callback_info info, stdlib_complex128_t (*fcn)( stdlib_complex128_t, int32_t ) ) {
605
- napi_status status;
606
-
607
- size_t argc = 2;
608
- napi_value argv[ 2 ];
609
- status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
610
- assert( status == napi_ok );
611
-
612
- if ( argc < 2 ) {
613
- status = napi_throw_error( env, NULL, "invalid invocation. Must provide two arguments." );
614
- assert( status == napi_ok );
615
- return NULL;
616
- }
617
-
618
- bool hprop;
619
- status = napi_has_named_property( env, argv[ 0 ], "re", &hprop );
620
- assert( status == napi_ok );
621
- if ( !hprop ) {
622
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component." );
623
- assert( status == napi_ok );
624
- return NULL;
625
- }
626
-
627
- napi_value xre;
628
- status = napi_get_named_property( env, argv[ 0 ], "re", &xre );
629
- assert( status == napi_ok );
630
-
631
- napi_valuetype xretype;
632
- status = napi_typeof( env, xre, &xretype );
633
- assert( status == napi_ok );
634
- if ( xretype != napi_number ) {
635
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component which is a number." );
636
- assert( status == napi_ok );
637
- return NULL;
638
- }
639
-
640
- status = napi_has_named_property( env, argv[ 0 ], "im", &hprop );
641
- assert( status == napi_ok );
642
- if ( !hprop ) {
643
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component." );
644
- assert( status == napi_ok );
645
- return NULL;
646
- }
647
-
648
- napi_value xim;
649
- status = napi_get_named_property( env, argv[ 0 ], "im", &xim );
650
- assert( status == napi_ok );
651
-
652
- napi_valuetype ximtype;
653
- status = napi_typeof( env, xim, &ximtype );
654
- assert( status == napi_ok );
655
- if ( ximtype != napi_number ) {
656
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component which a number." );
657
- assert( status == napi_ok );
658
- return NULL;
659
- }
660
-
661
- napi_valuetype vtype1;
662
- status = napi_typeof( env, argv[ 1 ], &vtype1 );
663
- assert( status == napi_ok );
664
- if ( vtype1 != napi_number ) {
665
- status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
666
- assert( status == napi_ok );
667
- return NULL;
668
- }
669
-
670
- double re0;
671
- status = napi_get_value_double( env, xre, &re0 );
672
- assert( status == napi_ok );
673
-
674
- double im0;
675
- status = napi_get_value_double( env, xim, &im0 );
676
- assert( status == napi_ok );
677
-
678
- int32_t y;
679
- status = napi_get_value_int32( env, argv[ 1 ], &y );
680
- assert( status == napi_ok );
681
-
682
- stdlib_complex128_t v = fcn( stdlib_complex128( re0, im0 ), y );
683
- double re;
684
- double im;
685
- stdlib_reim( v, &re, &im );
686
-
687
- napi_value obj;
688
- status = napi_create_object( env, &obj );
689
- assert( status == napi_ok );
690
-
691
- napi_value vre;
692
- status = napi_create_double( env, re, &vre );
693
- assert( status == napi_ok );
694
-
695
- status = napi_set_named_property( env, obj, "re", vre );
696
- assert( status == napi_ok );
697
-
698
- napi_value vim;
699
- status = napi_create_double( env, im, &vim );
700
- assert( status == napi_ok );
701
-
702
- status = napi_set_named_property( env, obj, "im", vim );
703
- assert( status == napi_ok );
704
-
705
- return obj;
706
- }
707
-
708
- /**
709
- * Invokes a binary function accepting a single-precision complex floating-point number and a signed 32-bit integer and returning a single-precision complex floating-point number.
710
- *
711
- * ## Notes
712
- *
713
- * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
714
- *
715
- * - `x`: input value.
716
- * - `y`: input value.
717
- *
718
- * @param env environment under which the function is invoked
719
- * @param info callback data
720
- * @param fcn binary function
721
- * @return function return value as a Node-API complex-like object
722
- */
723
- napi_value stdlib_math_base_napi_ci_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t, int32_t ) ) {
724
- napi_status status;
725
-
726
- size_t argc = 2;
727
- napi_value argv[ 2 ];
728
- status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
729
- assert( status == napi_ok );
730
-
731
- if ( argc < 2 ) {
732
- status = napi_throw_error( env, NULL, "invalid invocation. Must provide two arguments." );
733
- assert( status == napi_ok );
734
- return NULL;
735
- }
736
-
737
- bool hprop;
738
- status = napi_has_named_property( env, argv[ 0 ], "re", &hprop );
739
- assert( status == napi_ok );
740
- if ( !hprop ) {
741
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component." );
742
- assert( status == napi_ok );
743
- return NULL;
744
- }
745
-
746
- napi_value xre;
747
- status = napi_get_named_property( env, argv[ 0 ], "re", &xre );
748
- assert( status == napi_ok );
749
-
750
- napi_valuetype xretype;
751
- status = napi_typeof( env, xre, &xretype );
752
- assert( status == napi_ok );
753
- if ( xretype != napi_number ) {
754
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component which is a number." );
755
- assert( status == napi_ok );
756
- return NULL;
757
- }
758
-
759
- status = napi_has_named_property( env, argv[ 0 ], "im", &hprop );
760
- assert( status == napi_ok );
761
- if ( !hprop ) {
762
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component." );
763
- assert( status == napi_ok );
764
- return NULL;
765
- }
766
-
767
- napi_value xim;
768
- status = napi_get_named_property( env, argv[ 0 ], "im", &xim );
769
- assert( status == napi_ok );
770
-
771
- napi_valuetype ximtype;
772
- status = napi_typeof( env, xim, &ximtype );
773
- assert( status == napi_ok );
774
- if ( ximtype != napi_number ) {
775
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component which a number." );
776
- assert( status == napi_ok );
777
- return NULL;
778
- }
779
-
780
- napi_valuetype vtype1;
781
- status = napi_typeof( env, argv[ 1 ], &vtype1 );
782
- assert( status == napi_ok );
783
- if ( vtype1 != napi_number ) {
784
- status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
785
- assert( status == napi_ok );
786
- return NULL;
787
- }
788
-
789
- double re0;
790
- status = napi_get_value_double( env, xre, &re0 );
791
- assert( status == napi_ok );
792
-
793
- double im0;
794
- status = napi_get_value_double( env, xim, &im0 );
795
- assert( status == napi_ok );
796
-
797
- int32_t y;
798
- status = napi_get_value_int32( env, argv[ 1 ], &y );
799
- assert( status == napi_ok );
800
-
801
- stdlib_complex64_t v = fcn( stdlib_complex64( (float)re0, (float)im0 ), y );
802
- float re;
803
- float im;
804
- stdlib_reimf( v, &re, &im );
805
-
806
- napi_value obj;
807
- status = napi_create_object( env, &obj );
808
- assert( status == napi_ok );
809
-
810
- napi_value vre;
811
- status = napi_create_double( env, (double)re, &vre );
812
- assert( status == napi_ok );
813
-
814
- status = napi_set_named_property( env, obj, "re", vre );
815
- assert( status == napi_ok );
816
-
817
- napi_value vim;
818
- status = napi_create_double( env, (double)im, &vim );
819
- assert( status == napi_ok );
820
-
821
- status = napi_set_named_property( env, obj, "im", vim );
822
- assert( status == napi_ok );
823
-
824
- return obj;
825
- }
826
-
827
- /**
828
- * Invokes a binary function accepting a double-precision complex floating-point number and a double-precision floating-point number and returning a double-precision complex floating-point number.
829
- *
830
- * ## Notes
831
- *
832
- * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
833
- *
834
- * - `x`: input value.
835
- * - `y`: input value.
836
- *
837
- * @param env environment under which the function is invoked
838
- * @param info callback data
839
- * @param fcn binary function
840
- * @return function return value as a Node-API complex-like object
841
- */
842
- napi_value stdlib_math_base_napi_zd_z( napi_env env, napi_callback_info info, stdlib_complex128_t (*fcn)( stdlib_complex128_t, double ) ) {
843
- napi_status status;
844
-
845
- size_t argc = 2;
846
- napi_value argv[ 2 ];
847
- status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
848
- assert( status == napi_ok );
849
-
850
- if ( argc < 2 ) {
851
- status = napi_throw_error( env, NULL, "invalid invocation. Must provide two arguments." );
852
- assert( status == napi_ok );
853
- return NULL;
854
- }
855
-
856
- bool hprop;
857
- status = napi_has_named_property( env, argv[ 0 ], "re", &hprop );
858
- assert( status == napi_ok );
859
- if ( !hprop ) {
860
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component." );
861
- assert( status == napi_ok );
862
- return NULL;
863
- }
864
-
865
- napi_value xre;
866
- status = napi_get_named_property( env, argv[ 0 ], "re", &xre );
867
- assert( status == napi_ok );
868
-
869
- napi_valuetype xretype;
870
- status = napi_typeof( env, xre, &xretype );
871
- assert( status == napi_ok );
872
- if ( xretype != napi_number ) {
873
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component which is a number." );
874
- assert( status == napi_ok );
875
- return NULL;
876
- }
877
-
878
- status = napi_has_named_property( env, argv[ 0 ], "im", &hprop );
879
- assert( status == napi_ok );
880
- if ( !hprop ) {
881
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component." );
882
- assert( status == napi_ok );
883
- return NULL;
884
- }
885
-
886
- napi_value xim;
887
- status = napi_get_named_property( env, argv[ 0 ], "im", &xim );
888
- assert( status == napi_ok );
889
-
890
- napi_valuetype ximtype;
891
- status = napi_typeof( env, xim, &ximtype );
892
- assert( status == napi_ok );
893
- if ( ximtype != napi_number ) {
894
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component which a number." );
895
- assert( status == napi_ok );
896
- return NULL;
897
- }
898
-
899
- napi_valuetype vtype1;
900
- status = napi_typeof( env, argv[ 1 ], &vtype1 );
901
- assert( status == napi_ok );
902
- if ( vtype1 != napi_number ) {
903
- status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
904
- assert( status == napi_ok );
905
- return NULL;
906
- }
907
-
908
- double re0;
909
- status = napi_get_value_double( env, xre, &re0 );
910
- assert( status == napi_ok );
911
-
912
- double im0;
913
- status = napi_get_value_double( env, xim, &im0 );
914
- assert( status == napi_ok );
915
-
916
- double y;
917
- status = napi_get_value_double( env, argv[ 1 ], &y );
918
- assert( status == napi_ok );
919
-
920
- stdlib_complex128_t v = fcn( stdlib_complex128( re0, im0 ), y );
921
- double re;
922
- double im;
923
- stdlib_reim( v, &re, &im );
924
-
925
- napi_value obj;
926
- status = napi_create_object( env, &obj );
927
- assert( status == napi_ok );
928
-
929
- napi_value vre;
930
- status = napi_create_double( env, re, &vre );
931
- assert( status == napi_ok );
932
-
933
- status = napi_set_named_property( env, obj, "re", vre );
934
- assert( status == napi_ok );
935
-
936
- napi_value vim;
937
- status = napi_create_double( env, im, &vim );
938
- assert( status == napi_ok );
939
-
940
- status = napi_set_named_property( env, obj, "im", vim );
941
- assert( status == napi_ok );
942
-
943
- return obj;
944
- }
945
-
946
- /**
947
- * Invokes a binary function accepting a single-precision complex floating-point number and a single-precision floating-point number and returning a single-precision complex floating-point number.
948
- *
949
- * ## Notes
950
- *
951
- * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
952
- *
953
- * - `x`: input value.
954
- * - `y`: input value.
955
- *
956
- * @param env environment under which the function is invoked
957
- * @param info callback data
958
- * @param fcn binary function
959
- * @return function return value as a Node-API complex-like object
960
- */
961
- napi_value stdlib_math_base_napi_cf_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t, float ) ) {
962
- napi_status status;
963
-
964
- size_t argc = 2;
965
- napi_value argv[ 2 ];
966
- status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
967
- assert( status == napi_ok );
968
-
969
- if ( argc < 2 ) {
970
- status = napi_throw_error( env, NULL, "invalid invocation. Must provide two arguments." );
971
- assert( status == napi_ok );
972
- return NULL;
973
- }
974
-
975
- bool hprop;
976
- status = napi_has_named_property( env, argv[ 0 ], "re", &hprop );
977
- assert( status == napi_ok );
978
- if ( !hprop ) {
979
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component." );
980
- assert( status == napi_ok );
981
- return NULL;
982
- }
983
-
984
- napi_value xre;
985
- status = napi_get_named_property( env, argv[ 0 ], "re", &xre );
986
- assert( status == napi_ok );
987
-
988
- napi_valuetype xretype;
989
- status = napi_typeof( env, xre, &xretype );
990
- assert( status == napi_ok );
991
- if ( xretype != napi_number ) {
992
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component which is a number." );
993
- assert( status == napi_ok );
994
- return NULL;
995
- }
996
-
997
- status = napi_has_named_property( env, argv[ 0 ], "im", &hprop );
998
- assert( status == napi_ok );
999
- if ( !hprop ) {
1000
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component." );
1001
- assert( status == napi_ok );
1002
- return NULL;
1003
- }
1004
-
1005
- napi_value xim;
1006
- status = napi_get_named_property( env, argv[ 0 ], "im", &xim );
1007
- assert( status == napi_ok );
1008
-
1009
- napi_valuetype ximtype;
1010
- status = napi_typeof( env, xim, &ximtype );
1011
- assert( status == napi_ok );
1012
- if ( ximtype != napi_number ) {
1013
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component which a number." );
1014
- assert( status == napi_ok );
1015
- return NULL;
1016
- }
1017
-
1018
- napi_valuetype vtype1;
1019
- status = napi_typeof( env, argv[ 1 ], &vtype1 );
1020
- assert( status == napi_ok );
1021
- if ( vtype1 != napi_number ) {
1022
- status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
1023
- assert( status == napi_ok );
1024
- return NULL;
1025
- }
1026
-
1027
- double re0;
1028
- status = napi_get_value_double( env, xre, &re0 );
1029
- assert( status == napi_ok );
1030
-
1031
- double im0;
1032
- status = napi_get_value_double( env, xim, &im0 );
1033
- assert( status == napi_ok );
1034
-
1035
- double y;
1036
- status = napi_get_value_double( env, argv[ 1 ], &y );
1037
- assert( status == napi_ok );
1038
-
1039
- stdlib_complex64_t v = fcn( stdlib_complex64( (float)re0, (float)im0 ), (float)y );
1040
- float re;
1041
- float im;
1042
- stdlib_reimf( v, &re, &im );
1043
-
1044
- napi_value obj;
1045
- status = napi_create_object( env, &obj );
1046
- assert( status == napi_ok );
1047
-
1048
- napi_value vre;
1049
- status = napi_create_double( env, (double)re, &vre );
1050
- assert( status == napi_ok );
1051
-
1052
- status = napi_set_named_property( env, obj, "re", vre );
1053
- assert( status == napi_ok );
1054
-
1055
- napi_value vim;
1056
- status = napi_create_double( env, (double)im, &vim );
1057
- assert( status == napi_ok );
1058
-
1059
- status = napi_set_named_property( env, obj, "im", vim );
1060
- assert( status == napi_ok );
1061
-
1062
- return obj;
1063
- }