@stdlib/math-base-napi-unary 0.2.3 → 0.2.4

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 (40) hide show
  1. package/NOTICE +1 -1
  2. package/README.md +710 -144
  3. package/include/stdlib/math/base/napi/unary/b_b.h +84 -0
  4. package/include/stdlib/math/base/napi/unary/c_c.h +93 -0
  5. package/include/stdlib/math/base/napi/unary/c_f.h +84 -0
  6. package/include/stdlib/math/base/napi/unary/d_d.h +81 -0
  7. package/include/stdlib/math/base/napi/unary/d_f.h +81 -0
  8. package/include/stdlib/math/base/napi/unary/f_f.h +81 -0
  9. package/include/stdlib/math/base/napi/unary/f_i.h +84 -0
  10. package/include/stdlib/math/base/napi/unary/h_h.h +84 -0
  11. package/include/stdlib/math/base/napi/unary/i_d.h +84 -0
  12. package/include/stdlib/math/base/napi/unary/i_f.h +84 -0
  13. package/include/stdlib/math/base/napi/unary/i_i.h +84 -0
  14. package/include/stdlib/math/base/napi/unary/k_k.h +84 -0
  15. package/include/stdlib/math/base/napi/unary/s_s.h +84 -0
  16. package/include/stdlib/math/base/napi/unary/t_t.h +84 -0
  17. package/include/stdlib/math/base/napi/unary/u_u.h +84 -0
  18. package/include/stdlib/math/base/napi/unary/z_d.h +84 -0
  19. package/include/stdlib/math/base/napi/unary/z_z.h +93 -0
  20. package/include/stdlib/math/base/napi/unary.h +18 -406
  21. package/manifest.json +56 -37
  22. package/package.json +6 -3
  23. package/src/b_b.c +71 -0
  24. package/src/c_c.c +129 -0
  25. package/src/c_f.c +109 -0
  26. package/src/d_d.c +69 -0
  27. package/src/d_f.c +69 -0
  28. package/src/f_f.c +69 -0
  29. package/src/f_i.c +70 -0
  30. package/src/h_h.c +74 -0
  31. package/src/i_d.c +70 -0
  32. package/src/i_f.c +70 -0
  33. package/src/i_i.c +70 -0
  34. package/src/k_k.c +70 -0
  35. package/src/s_s.c +71 -0
  36. package/src/t_t.c +70 -0
  37. package/src/u_u.c +70 -0
  38. package/src/z_d.c +109 -0
  39. package/src/z_z.c +129 -0
  40. package/src/main.c +0 -601
package/src/i_d.c ADDED
@@ -0,0 +1,70 @@
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/unary/i_d.h"
20
+ #include <node_api.h>
21
+ #include <assert.h>
22
+ #include <stdint.h>
23
+
24
+ /**
25
+ * Invokes a unary function accepting a signed 32-bit integer and returning a single-precision floating-point number.
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
+ *
33
+ * @param env environment under which the function is invoked
34
+ * @param info callback data
35
+ * @param fcn unary function
36
+ * @return function return value as a Node-API double-precision floating-point number
37
+ */
38
+ napi_value stdlib_math_base_napi_i_d( napi_env env, napi_callback_info info, double (*fcn)( int32_t ) ) {
39
+ napi_status status;
40
+
41
+ size_t argc = 1;
42
+ napi_value argv[ 1 ];
43
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
44
+ assert( status == napi_ok );
45
+
46
+ if ( argc < 1 ) {
47
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide a number." );
48
+ assert( status == napi_ok );
49
+ return NULL;
50
+ }
51
+
52
+ napi_valuetype vtype0;
53
+ status = napi_typeof( env, argv[ 0 ], &vtype0 );
54
+ assert( status == napi_ok );
55
+ if ( vtype0 != napi_number ) {
56
+ status = napi_throw_type_error( env, NULL, "invalid argument. Must provide a number." );
57
+ assert( status == napi_ok );
58
+ return NULL;
59
+ }
60
+
61
+ int32_t x;
62
+ status = napi_get_value_int32( env, argv[ 0 ], &x );
63
+ assert( status == napi_ok );
64
+
65
+ napi_value v;
66
+ status = napi_create_double( env, fcn( x ), &v );
67
+ assert( status == napi_ok );
68
+
69
+ return v;
70
+ }
package/src/i_f.c ADDED
@@ -0,0 +1,70 @@
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/unary/i_f.h"
20
+ #include <node_api.h>
21
+ #include <assert.h>
22
+ #include <stdint.h>
23
+
24
+ /**
25
+ * Invokes a unary function accepting a signed 32-bit integer and returning a single-precision floating-point number.
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
+ *
33
+ * @param env environment under which the function is invoked
34
+ * @param info callback data
35
+ * @param fcn unary function
36
+ * @return function return value as a Node-API double-precision floating-point number
37
+ */
38
+ napi_value stdlib_math_base_napi_i_f( napi_env env, napi_callback_info info, float (*fcn)( int32_t ) ) {
39
+ napi_status status;
40
+
41
+ size_t argc = 1;
42
+ napi_value argv[ 1 ];
43
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
44
+ assert( status == napi_ok );
45
+
46
+ if ( argc < 1 ) {
47
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide a number." );
48
+ assert( status == napi_ok );
49
+ return NULL;
50
+ }
51
+
52
+ napi_valuetype vtype0;
53
+ status = napi_typeof( env, argv[ 0 ], &vtype0 );
54
+ assert( status == napi_ok );
55
+ if ( vtype0 != napi_number ) {
56
+ status = napi_throw_type_error( env, NULL, "invalid argument. Must provide a number." );
57
+ assert( status == napi_ok );
58
+ return NULL;
59
+ }
60
+
61
+ int32_t x;
62
+ status = napi_get_value_int32( env, argv[ 0 ], &x );
63
+ assert( status == napi_ok );
64
+
65
+ napi_value v;
66
+ status = napi_create_double( env, (double)fcn( x ), &v );
67
+ assert( status == napi_ok );
68
+
69
+ return v;
70
+ }
package/src/i_i.c ADDED
@@ -0,0 +1,70 @@
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/unary/i_i.h"
20
+ #include <node_api.h>
21
+ #include <assert.h>
22
+ #include <stdint.h>
23
+
24
+ /**
25
+ * Invokes a unary function accepting and returning signed 32-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
+ *
33
+ * @param env environment under which the function is invoked
34
+ * @param info callback data
35
+ * @param fcn unary function
36
+ * @return function return value as a Node-API signed 32-bit integer
37
+ */
38
+ napi_value stdlib_math_base_napi_i_i( napi_env env, napi_callback_info info, int32_t (*fcn)( int32_t ) ) {
39
+ napi_status status;
40
+
41
+ size_t argc = 1;
42
+ napi_value argv[ 1 ];
43
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
44
+ assert( status == napi_ok );
45
+
46
+ if ( argc < 1 ) {
47
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide a number." );
48
+ assert( status == napi_ok );
49
+ return NULL;
50
+ }
51
+
52
+ napi_valuetype vtype0;
53
+ status = napi_typeof( env, argv[ 0 ], &vtype0 );
54
+ assert( status == napi_ok );
55
+ if ( vtype0 != napi_number ) {
56
+ status = napi_throw_type_error( env, NULL, "invalid argument. Must provide a number." );
57
+ assert( status == napi_ok );
58
+ return NULL;
59
+ }
60
+
61
+ int32_t x;
62
+ status = napi_get_value_int32( env, argv[ 0 ], &x );
63
+ assert( status == napi_ok );
64
+
65
+ napi_value v;
66
+ status = napi_create_int32( env, fcn( x ), &v );
67
+ assert( status == napi_ok );
68
+
69
+ return v;
70
+ }
package/src/k_k.c ADDED
@@ -0,0 +1,70 @@
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/unary/k_k.h"
20
+ #include <node_api.h>
21
+ #include <assert.h>
22
+ #include <stdint.h>
23
+
24
+ /**
25
+ * Invokes a unary function accepting and returning signed 16-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
+ *
33
+ * @param env environment under which the function is invoked
34
+ * @param info callback data
35
+ * @param fcn unary function
36
+ * @return function return value as a Node-API signed 32-bit integer
37
+ */
38
+ napi_value stdlib_math_base_napi_k_k( napi_env env, napi_callback_info info, int16_t (*fcn)( int16_t ) ) {
39
+ napi_status status;
40
+
41
+ size_t argc = 1;
42
+ napi_value argv[ 1 ];
43
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
44
+ assert( status == napi_ok );
45
+
46
+ if ( argc < 1 ) {
47
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide a number." );
48
+ assert( status == napi_ok );
49
+ return NULL;
50
+ }
51
+
52
+ napi_valuetype vtype0;
53
+ status = napi_typeof( env, argv[ 0 ], &vtype0 );
54
+ assert( status == napi_ok );
55
+ if ( vtype0 != napi_number ) {
56
+ status = napi_throw_type_error( env, NULL, "invalid argument. Must provide a number." );
57
+ assert( status == napi_ok );
58
+ return NULL;
59
+ }
60
+
61
+ int32_t x;
62
+ status = napi_get_value_int32( env, argv[ 0 ], &x );
63
+ assert( status == napi_ok );
64
+
65
+ napi_value v;
66
+ status = napi_create_int32( env, (int32_t)fcn( (int16_t)x ), &v );
67
+ assert( status == napi_ok );
68
+
69
+ return v;
70
+ }
package/src/s_s.c ADDED
@@ -0,0 +1,71 @@
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/unary/s_s.h"
20
+ #include <node_api.h>
21
+ #include <assert.h>
22
+ #include <stdint.h>
23
+
24
+ /**
25
+ * Invokes a unary function accepting and returning signed 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
+ *
33
+ * @param env environment under which the function is invoked
34
+ * @param info callback data
35
+ * @param fcn unary function
36
+ * @return function return value as a Node-API signed 32-bit integer
37
+ */
38
+ napi_value stdlib_math_base_napi_s_s( napi_env env, napi_callback_info info, int8_t (*fcn)( int8_t ) ) {
39
+ napi_status status;
40
+
41
+ size_t argc = 1;
42
+ napi_value argv[ 1 ];
43
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
44
+ assert( status == napi_ok );
45
+
46
+ if ( argc < 1 ) {
47
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide a number." );
48
+ assert( status == napi_ok );
49
+ return NULL;
50
+ }
51
+
52
+ napi_valuetype vtype0;
53
+ status = napi_typeof( env, argv[ 0 ], &vtype0 );
54
+ assert( status == napi_ok );
55
+ if ( vtype0 != napi_number ) {
56
+ status = napi_throw_type_error( env, NULL, "invalid argument. Must provide a number." );
57
+ assert( status == napi_ok );
58
+ return NULL;
59
+ }
60
+
61
+ int32_t x;
62
+ status = napi_get_value_int32( env, argv[ 0 ], &x );
63
+ assert( status == napi_ok );
64
+
65
+ napi_value v;
66
+ status = napi_create_int32( env, (int32_t)fcn( (int8_t)x ), &v );
67
+ assert( status == napi_ok );
68
+
69
+ return v;
70
+ }
71
+
package/src/t_t.c ADDED
@@ -0,0 +1,70 @@
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/unary/t_t.h"
20
+ #include <node_api.h>
21
+ #include <assert.h>
22
+ #include <stdint.h>
23
+
24
+ /**
25
+ * Invokes a unary function accepting and returning unsigned 16-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
+ *
33
+ * @param env environment under which the function is invoked
34
+ * @param info callback data
35
+ * @param fcn unary function
36
+ * @return function return value as a Node-API unsigned 32-bit integer
37
+ */
38
+ napi_value stdlib_math_base_napi_t_t( napi_env env, napi_callback_info info, uint16_t (*fcn)( uint16_t ) ) {
39
+ napi_status status;
40
+
41
+ size_t argc = 1;
42
+ napi_value argv[ 1 ];
43
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
44
+ assert( status == napi_ok );
45
+
46
+ if ( argc < 1 ) {
47
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide a number." );
48
+ assert( status == napi_ok );
49
+ return NULL;
50
+ }
51
+
52
+ napi_valuetype vtype0;
53
+ status = napi_typeof( env, argv[ 0 ], &vtype0 );
54
+ assert( status == napi_ok );
55
+ if ( vtype0 != napi_number ) {
56
+ status = napi_throw_type_error( env, NULL, "invalid argument. Must provide a number." );
57
+ assert( status == napi_ok );
58
+ return NULL;
59
+ }
60
+
61
+ uint32_t x;
62
+ status = napi_get_value_uint32( env, argv[ 0 ], &x );
63
+ assert( status == napi_ok );
64
+
65
+ napi_value v;
66
+ status = napi_create_uint32( env, (uint32_t)fcn( (uint16_t)x ), &v );
67
+ assert( status == napi_ok );
68
+
69
+ return v;
70
+ }
package/src/u_u.c ADDED
@@ -0,0 +1,70 @@
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/unary/u_u.h"
20
+ #include <node_api.h>
21
+ #include <assert.h>
22
+ #include <stdint.h>
23
+
24
+ /**
25
+ * Invokes a unary function accepting and returning unsigned 32-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
+ *
33
+ * @param env environment under which the function is invoked
34
+ * @param info callback data
35
+ * @param fcn unary function
36
+ * @return function return value as a Node-API unsigned 32-bit integer
37
+ */
38
+ napi_value stdlib_math_base_napi_u_u( napi_env env, napi_callback_info info, uint32_t (*fcn)( uint32_t ) ) {
39
+ napi_status status;
40
+
41
+ size_t argc = 1;
42
+ napi_value argv[ 1 ];
43
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
44
+ assert( status == napi_ok );
45
+
46
+ if ( argc < 1 ) {
47
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide a number." );
48
+ assert( status == napi_ok );
49
+ return NULL;
50
+ }
51
+
52
+ napi_valuetype vtype0;
53
+ status = napi_typeof( env, argv[ 0 ], &vtype0 );
54
+ assert( status == napi_ok );
55
+ if ( vtype0 != napi_number ) {
56
+ status = napi_throw_type_error( env, NULL, "invalid argument. Must provide a number." );
57
+ assert( status == napi_ok );
58
+ return NULL;
59
+ }
60
+
61
+ uint32_t x;
62
+ status = napi_get_value_uint32( env, argv[ 0 ], &x );
63
+ assert( status == napi_ok );
64
+
65
+ napi_value v;
66
+ status = napi_create_uint32( env, fcn( x ), &v );
67
+ assert( status == napi_ok );
68
+
69
+ return v;
70
+ }
package/src/z_d.c ADDED
@@ -0,0 +1,109 @@
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/unary/z_d.h"
20
+ #include "stdlib/complex/float64/ctor.h"
21
+ #include <node_api.h>
22
+ #include <assert.h>
23
+ #include <stdbool.h>
24
+
25
+ /**
26
+ * Invokes a unary function accepting a double-precision complex floating-point number and returning a double-precision floating-point number.
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
+ *
34
+ * @param env environment under which the function is invoked
35
+ * @param info callback data
36
+ * @param fcn unary function
37
+ * @return function return value as a Node-API complex-like object
38
+ */
39
+ napi_value stdlib_math_base_napi_z_d( napi_env env, napi_callback_info info, double (*fcn)( stdlib_complex128_t ) ) {
40
+ napi_status status;
41
+
42
+ size_t argc = 1;
43
+ napi_value argv[ 1 ];
44
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
45
+ assert( status == napi_ok );
46
+
47
+ if ( argc < 1 ) {
48
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide a complex number." );
49
+ assert( status == napi_ok );
50
+ return NULL;
51
+ }
52
+
53
+ bool hprop;
54
+ status = napi_has_named_property( env, argv[ 0 ], "re", &hprop );
55
+ assert( status == napi_ok );
56
+ if ( !hprop ) {
57
+ status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have a real component." );
58
+ assert( status == napi_ok );
59
+ return NULL;
60
+ }
61
+
62
+ napi_value xre;
63
+ status = napi_get_named_property( env, argv[ 0 ], "re", &xre );
64
+ assert( status == napi_ok );
65
+
66
+ napi_valuetype xretype;
67
+ status = napi_typeof( env, xre, &xretype );
68
+ assert( status == napi_ok );
69
+ if ( xretype != napi_number ) {
70
+ status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have a real component which is a number." );
71
+ assert( status == napi_ok );
72
+ return NULL;
73
+ }
74
+
75
+ status = napi_has_named_property( env, argv[ 0 ], "im", &hprop );
76
+ assert( status == napi_ok );
77
+ if ( !hprop ) {
78
+ status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have an imaginary component." );
79
+ assert( status == napi_ok );
80
+ return NULL;
81
+ }
82
+
83
+ napi_value xim;
84
+ status = napi_get_named_property( env, argv[ 0 ], "im", &xim );
85
+ assert( status == napi_ok );
86
+
87
+ napi_valuetype ximtype;
88
+ status = napi_typeof( env, xim, &ximtype );
89
+ assert( status == napi_ok );
90
+ if ( ximtype != napi_number ) {
91
+ status = napi_throw_type_error( env, NULL, "invalid argument. Argument must have an imaginary component which a number." );
92
+ assert( status == napi_ok );
93
+ return NULL;
94
+ }
95
+
96
+ double re;
97
+ status = napi_get_value_double( env, xre, &re );
98
+ assert( status == napi_ok );
99
+
100
+ double im;
101
+ status = napi_get_value_double( env, xim, &im );
102
+ assert( status == napi_ok );
103
+
104
+ napi_value v;
105
+ status = napi_create_double( env, fcn( stdlib_complex128( re, im ) ), &v );
106
+ assert( status == napi_ok );
107
+
108
+ return v;
109
+ }