@stdlib/math-base-napi-binary 0.3.0 → 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 (50) hide show
  1. package/NOTICE +1 -1
  2. package/README.md +1065 -284
  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 -621
  26. package/manifest.json +56 -36
  27. package/package.json +1 -1
  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/src/main.c +0 -1187
package/manifest.json CHANGED
@@ -1,43 +1,63 @@
1
1
  {
2
- "options": {},
3
- "fields": [
4
- {
5
- "field": "src",
6
- "resolve": true,
7
- "relative": true
8
- },
9
- {
10
- "field": "include",
11
- "resolve": true,
12
- "relative": true
13
- },
14
- {
15
- "field": "libraries",
16
- "resolve": false,
17
- "relative": false
18
- },
19
- {
20
- "field": "libpath",
21
- "resolve": true,
22
- "relative": false
23
- }
24
- ],
25
- "confs": [
26
- {
27
- "src": [
28
- "./src/main.c"
29
- ],
30
- "include": [
31
- "./include"
32
- ],
33
- "libraries": [],
34
- "libpath": [],
35
- "dependencies": [
2
+ "options": {},
3
+ "fields": [
4
+ {
5
+ "field": "src",
6
+ "resolve": true,
7
+ "relative": true
8
+ },
9
+ {
10
+ "field": "include",
11
+ "resolve": true,
12
+ "relative": true
13
+ },
14
+ {
15
+ "field": "libraries",
16
+ "resolve": false,
17
+ "relative": false
18
+ },
19
+ {
20
+ "field": "libpath",
21
+ "resolve": true,
22
+ "relative": false
23
+ }
24
+ ],
25
+ "confs": [
26
+ {
27
+ "src": [
28
+ "./src/bb_b.c",
29
+ "./src/cc_c.c",
30
+ "./src/cf_c.c",
31
+ "./src/ci_c.c",
32
+ "./src/dd_d.c",
33
+ "./src/di_d.c",
34
+ "./src/dz_z.c",
35
+ "./src/fc_c.c",
36
+ "./src/ff_f.c",
37
+ "./src/fi_f.c",
38
+ "./src/id_d.c",
39
+ "./src/ii_d.c",
40
+ "./src/ii_f.c",
41
+ "./src/kk_k.c",
42
+ "./src/ll_d.c",
43
+ "./src/ss_s.c",
44
+ "./src/tt_t.c",
45
+ "./src/uu_u.c",
46
+ "./src/zd_z.c",
47
+ "./src/zi_z.c",
48
+ "./src/zz_z.c"
49
+ ],
50
+ "include": [
51
+ "./include"
52
+ ],
53
+ "libraries": [],
54
+ "libpath": [],
55
+ "dependencies": [
36
56
  "@stdlib/complex-float32-ctor",
37
57
  "@stdlib/complex-float64-ctor",
38
58
  "@stdlib/complex-float64-reim",
39
59
  "@stdlib/complex-float32-reim"
40
60
  ]
41
- }
42
- ]
61
+ }
62
+ ]
43
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/math-base-napi-binary",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
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": {
package/src/bb_b.c ADDED
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #include "stdlib/math/base/napi/binary/bb_b.h"
20
+ #include <node_api.h>
21
+ #include <stdint.h>
22
+ #include <assert.h>
23
+
24
+ /**
25
+ * Invokes a binary function accepting and returning unsigned 8-bit integers.
26
+ *
27
+ * ## Notes
28
+ *
29
+ * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
30
+ *
31
+ * - `x`: input value.
32
+ * - `y`: input value.
33
+ *
34
+ * @param env environment under which the function is invoked
35
+ * @param info callback data
36
+ * @param fcn binary function
37
+ * @return function return value as a Node-API signed 32-bit integer
38
+ */
39
+ napi_value stdlib_math_base_napi_bb_b( napi_env env, napi_callback_info info, uint8_t (*fcn)( uint8_t, uint8_t ) ) {
40
+ napi_status status;
41
+
42
+ size_t argc = 2;
43
+ napi_value argv[ 2 ];
44
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
45
+ assert( status == napi_ok );
46
+
47
+ if ( argc < 2 ) {
48
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide two numbers." );
49
+ assert( status == napi_ok );
50
+ return NULL;
51
+ }
52
+
53
+ napi_valuetype vtype0;
54
+ status = napi_typeof( env, argv[ 0 ], &vtype0 );
55
+ assert( status == napi_ok );
56
+ if ( vtype0 != napi_number ) {
57
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
58
+ assert( status == napi_ok );
59
+ return NULL;
60
+ }
61
+
62
+ napi_valuetype vtype1;
63
+ status = napi_typeof( env, argv[ 1 ], &vtype1 );
64
+ assert( status == napi_ok );
65
+ if ( vtype1 != napi_number ) {
66
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
67
+ assert( status == napi_ok );
68
+ return NULL;
69
+ }
70
+
71
+ int32_t x;
72
+ status = napi_get_value_int32( env, argv[ 0 ], &x );
73
+ assert( status == napi_ok );
74
+
75
+ int32_t y;
76
+ status = napi_get_value_int32( env, argv[ 1 ], &y );
77
+ assert( status == napi_ok );
78
+
79
+ napi_value v;
80
+ status = napi_create_int32( env, (int32_t)fcn( (uint8_t)x, (uint8_t)y ), &v );
81
+ assert( status == napi_ok );
82
+
83
+ return v;
84
+ }
package/src/cc_c.c ADDED
@@ -0,0 +1,179 @@
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/cc_c.h"
20
+ #include "stdlib/complex/float32/ctor.h"
21
+ #include "stdlib/complex/float32/reim.h"
22
+ #include <node_api.h>
23
+ #include <assert.h>
24
+
25
+ /**
26
+ * Invokes a binary function accepting and returning single-precision complex floating-point numbers.
27
+ *
28
+ * ## Notes
29
+ *
30
+ * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
31
+ *
32
+ * - `x`: input value.
33
+ * - `y`: input value.
34
+ *
35
+ * @param env environment under which the function is invoked
36
+ * @param info callback data
37
+ * @param fcn binary function
38
+ * @return function return value as a Node-API complex-like object
39
+ */
40
+ 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 ) ) {
41
+ napi_status status;
42
+
43
+ size_t argc = 2;
44
+ napi_value argv[ 2 ];
45
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
46
+ assert( status == napi_ok );
47
+
48
+ if ( argc < 2 ) {
49
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide two complex numbers." );
50
+ assert( status == napi_ok );
51
+ return NULL;
52
+ }
53
+
54
+ bool hprop;
55
+ status = napi_has_named_property( env, argv[ 0 ], "re", &hprop );
56
+ assert( status == napi_ok );
57
+ if ( !hprop ) {
58
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component." );
59
+ assert( status == napi_ok );
60
+ return NULL;
61
+ }
62
+
63
+ napi_value xre;
64
+ status = napi_get_named_property( env, argv[ 0 ], "re", &xre );
65
+ assert( status == napi_ok );
66
+
67
+ napi_valuetype xretype;
68
+ status = napi_typeof( env, xre, &xretype );
69
+ assert( status == napi_ok );
70
+ if ( xretype != napi_number ) {
71
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component which is a number." );
72
+ assert( status == napi_ok );
73
+ return NULL;
74
+ }
75
+
76
+ status = napi_has_named_property( env, argv[ 0 ], "im", &hprop );
77
+ assert( status == napi_ok );
78
+ if ( !hprop ) {
79
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component." );
80
+ assert( status == napi_ok );
81
+ return NULL;
82
+ }
83
+
84
+ napi_value xim;
85
+ status = napi_get_named_property( env, argv[ 0 ], "im", &xim );
86
+ assert( status == napi_ok );
87
+
88
+ napi_valuetype ximtype;
89
+ status = napi_typeof( env, xim, &ximtype );
90
+ assert( status == napi_ok );
91
+ if ( ximtype != napi_number ) {
92
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component which a number." );
93
+ assert( status == napi_ok );
94
+ return NULL;
95
+ }
96
+
97
+ status = napi_has_named_property( env, argv[ 1 ], "re", &hprop );
98
+ assert( status == napi_ok );
99
+ if ( !hprop ) {
100
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have a real component." );
101
+ assert( status == napi_ok );
102
+ return NULL;
103
+ }
104
+
105
+ napi_value yre;
106
+ status = napi_get_named_property( env, argv[ 1 ], "re", &yre );
107
+ assert( status == napi_ok );
108
+
109
+ napi_valuetype yretype;
110
+ status = napi_typeof( env, yre, &yretype );
111
+ assert( status == napi_ok );
112
+ if ( yretype != napi_number ) {
113
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have a real component which is a number." );
114
+ assert( status == napi_ok );
115
+ return NULL;
116
+ }
117
+
118
+ status = napi_has_named_property( env, argv[ 1 ], "im", &hprop );
119
+ assert( status == napi_ok );
120
+ if ( !hprop ) {
121
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have an imaginary component." );
122
+ assert( status == napi_ok );
123
+ return NULL;
124
+ }
125
+
126
+ napi_value yim;
127
+ status = napi_get_named_property( env, argv[ 1 ], "im", &yim );
128
+ assert( status == napi_ok );
129
+
130
+ napi_valuetype yimtype;
131
+ status = napi_typeof( env, yim, &yimtype );
132
+ assert( status == napi_ok );
133
+ if ( yimtype != napi_number ) {
134
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have an imaginary component which a number." );
135
+ assert( status == napi_ok );
136
+ return NULL;
137
+ }
138
+
139
+ double re0;
140
+ status = napi_get_value_double( env, xre, &re0 );
141
+ assert( status == napi_ok );
142
+
143
+ double im0;
144
+ status = napi_get_value_double( env, xim, &im0 );
145
+ assert( status == napi_ok );
146
+
147
+ double re1;
148
+ status = napi_get_value_double( env, yre, &re1 );
149
+ assert( status == napi_ok );
150
+
151
+ double im1;
152
+ status = napi_get_value_double( env, yim, &im1 );
153
+ assert( status == napi_ok );
154
+
155
+ stdlib_complex64_t v = fcn( stdlib_complex64( (float)re0, (float)im0 ), stdlib_complex64( (float)re1, (float)im1 ) );
156
+ float re;
157
+ float im;
158
+ stdlib_complex64_reim( v, &re, &im );
159
+
160
+ napi_value obj;
161
+ status = napi_create_object( env, &obj );
162
+ assert( status == napi_ok );
163
+
164
+ napi_value vre;
165
+ status = napi_create_double( env, (double)re, &vre );
166
+ assert( status == napi_ok );
167
+
168
+ status = napi_set_named_property( env, obj, "re", vre );
169
+ assert( status == napi_ok );
170
+
171
+ napi_value vim;
172
+ status = napi_create_double( env, (double)im, &vim );
173
+ assert( status == napi_ok );
174
+
175
+ status = napi_set_named_property( env, obj, "im", vim );
176
+ assert( status == napi_ok );
177
+
178
+ return obj;
179
+ }
package/src/cf_c.c ADDED
@@ -0,0 +1,143 @@
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/cf_c.h"
20
+ #include "stdlib/complex/float32/ctor.h"
21
+ #include "stdlib/complex/float32/reim.h"
22
+ #include <node_api.h>
23
+ #include <stdint.h>
24
+ #include <assert.h>
25
+
26
+ /**
27
+ * 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.
28
+ *
29
+ * ## Notes
30
+ *
31
+ * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
32
+ *
33
+ * - `x`: input value.
34
+ * - `y`: input value.
35
+ *
36
+ * @param env environment under which the function is invoked
37
+ * @param info callback data
38
+ * @param fcn binary function
39
+ * @return function return value as a Node-API complex-like object
40
+ */
41
+ napi_value stdlib_math_base_napi_cf_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t, float ) ) {
42
+ napi_status status;
43
+
44
+ size_t argc = 2;
45
+ napi_value argv[ 2 ];
46
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
47
+ assert( status == napi_ok );
48
+
49
+ if ( argc < 2 ) {
50
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide two arguments." );
51
+ assert( status == napi_ok );
52
+ return NULL;
53
+ }
54
+
55
+ bool hprop;
56
+ status = napi_has_named_property( env, argv[ 0 ], "re", &hprop );
57
+ assert( status == napi_ok );
58
+ if ( !hprop ) {
59
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component." );
60
+ assert( status == napi_ok );
61
+ return NULL;
62
+ }
63
+
64
+ napi_value xre;
65
+ status = napi_get_named_property( env, argv[ 0 ], "re", &xre );
66
+ assert( status == napi_ok );
67
+
68
+ napi_valuetype xretype;
69
+ status = napi_typeof( env, xre, &xretype );
70
+ assert( status == napi_ok );
71
+ if ( xretype != napi_number ) {
72
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component which is a number." );
73
+ assert( status == napi_ok );
74
+ return NULL;
75
+ }
76
+
77
+ status = napi_has_named_property( env, argv[ 0 ], "im", &hprop );
78
+ assert( status == napi_ok );
79
+ if ( !hprop ) {
80
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component." );
81
+ assert( status == napi_ok );
82
+ return NULL;
83
+ }
84
+
85
+ napi_value xim;
86
+ status = napi_get_named_property( env, argv[ 0 ], "im", &xim );
87
+ assert( status == napi_ok );
88
+
89
+ napi_valuetype ximtype;
90
+ status = napi_typeof( env, xim, &ximtype );
91
+ assert( status == napi_ok );
92
+ if ( ximtype != napi_number ) {
93
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component which a number." );
94
+ assert( status == napi_ok );
95
+ return NULL;
96
+ }
97
+
98
+ napi_valuetype vtype1;
99
+ status = napi_typeof( env, argv[ 1 ], &vtype1 );
100
+ assert( status == napi_ok );
101
+ if ( vtype1 != napi_number ) {
102
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
103
+ assert( status == napi_ok );
104
+ return NULL;
105
+ }
106
+
107
+ double re0;
108
+ status = napi_get_value_double( env, xre, &re0 );
109
+ assert( status == napi_ok );
110
+
111
+ double im0;
112
+ status = napi_get_value_double( env, xim, &im0 );
113
+ assert( status == napi_ok );
114
+
115
+ double y;
116
+ status = napi_get_value_double( env, argv[ 1 ], &y );
117
+ assert( status == napi_ok );
118
+
119
+ stdlib_complex64_t v = fcn( stdlib_complex64( (float)re0, (float)im0 ), (float)y );
120
+ float re;
121
+ float im;
122
+ stdlib_complex64_reim( v, &re, &im );
123
+
124
+ napi_value obj;
125
+ status = napi_create_object( env, &obj );
126
+ assert( status == napi_ok );
127
+
128
+ napi_value vre;
129
+ status = napi_create_double( env, (double)re, &vre );
130
+ assert( status == napi_ok );
131
+
132
+ status = napi_set_named_property( env, obj, "re", vre );
133
+ assert( status == napi_ok );
134
+
135
+ napi_value vim;
136
+ status = napi_create_double( env, (double)im, &vim );
137
+ assert( status == napi_ok );
138
+
139
+ status = napi_set_named_property( env, obj, "im", vim );
140
+ assert( status == napi_ok );
141
+
142
+ return obj;
143
+ }
package/src/ci_c.c ADDED
@@ -0,0 +1,143 @@
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/ci_c.h"
20
+ #include "stdlib/complex/float32/ctor.h"
21
+ #include "stdlib/complex/float32/reim.h"
22
+ #include <node_api.h>
23
+ #include <stdint.h>
24
+ #include <assert.h>
25
+
26
+ /**
27
+ * 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.
28
+ *
29
+ * ## Notes
30
+ *
31
+ * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
32
+ *
33
+ * - `x`: input value.
34
+ * - `y`: input value.
35
+ *
36
+ * @param env environment under which the function is invoked
37
+ * @param info callback data
38
+ * @param fcn binary function
39
+ * @return function return value as a Node-API complex-like object
40
+ */
41
+ napi_value stdlib_math_base_napi_ci_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_t, int32_t ) ) {
42
+ napi_status status;
43
+
44
+ size_t argc = 2;
45
+ napi_value argv[ 2 ];
46
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
47
+ assert( status == napi_ok );
48
+
49
+ if ( argc < 2 ) {
50
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide two arguments." );
51
+ assert( status == napi_ok );
52
+ return NULL;
53
+ }
54
+
55
+ bool hprop;
56
+ status = napi_has_named_property( env, argv[ 0 ], "re", &hprop );
57
+ assert( status == napi_ok );
58
+ if ( !hprop ) {
59
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component." );
60
+ assert( status == napi_ok );
61
+ return NULL;
62
+ }
63
+
64
+ napi_value xre;
65
+ status = napi_get_named_property( env, argv[ 0 ], "re", &xre );
66
+ assert( status == napi_ok );
67
+
68
+ napi_valuetype xretype;
69
+ status = napi_typeof( env, xre, &xretype );
70
+ assert( status == napi_ok );
71
+ if ( xretype != napi_number ) {
72
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component which is a number." );
73
+ assert( status == napi_ok );
74
+ return NULL;
75
+ }
76
+
77
+ status = napi_has_named_property( env, argv[ 0 ], "im", &hprop );
78
+ assert( status == napi_ok );
79
+ if ( !hprop ) {
80
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component." );
81
+ assert( status == napi_ok );
82
+ return NULL;
83
+ }
84
+
85
+ napi_value xim;
86
+ status = napi_get_named_property( env, argv[ 0 ], "im", &xim );
87
+ assert( status == napi_ok );
88
+
89
+ napi_valuetype ximtype;
90
+ status = napi_typeof( env, xim, &ximtype );
91
+ assert( status == napi_ok );
92
+ if ( ximtype != napi_number ) {
93
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component which a number." );
94
+ assert( status == napi_ok );
95
+ return NULL;
96
+ }
97
+
98
+ napi_valuetype vtype1;
99
+ status = napi_typeof( env, argv[ 1 ], &vtype1 );
100
+ assert( status == napi_ok );
101
+ if ( vtype1 != napi_number ) {
102
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
103
+ assert( status == napi_ok );
104
+ return NULL;
105
+ }
106
+
107
+ double re0;
108
+ status = napi_get_value_double( env, xre, &re0 );
109
+ assert( status == napi_ok );
110
+
111
+ double im0;
112
+ status = napi_get_value_double( env, xim, &im0 );
113
+ assert( status == napi_ok );
114
+
115
+ int32_t y;
116
+ status = napi_get_value_int32( env, argv[ 1 ], &y );
117
+ assert( status == napi_ok );
118
+
119
+ stdlib_complex64_t v = fcn( stdlib_complex64( (float)re0, (float)im0 ), y );
120
+ float re;
121
+ float im;
122
+ stdlib_complex64_reim( v, &re, &im );
123
+
124
+ napi_value obj;
125
+ status = napi_create_object( env, &obj );
126
+ assert( status == napi_ok );
127
+
128
+ napi_value vre;
129
+ status = napi_create_double( env, (double)re, &vre );
130
+ assert( status == napi_ok );
131
+
132
+ status = napi_set_named_property( env, obj, "re", vre );
133
+ assert( status == napi_ok );
134
+
135
+ napi_value vim;
136
+ status = napi_create_double( env, (double)im, &vim );
137
+ assert( status == napi_ok );
138
+
139
+ status = napi_set_named_property( env, obj, "im", vim );
140
+ assert( status == napi_ok );
141
+
142
+ return obj;
143
+ }