@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/z_z.c ADDED
@@ -0,0 +1,129 @@
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_z.h"
20
+ #include "stdlib/complex/float64/ctor.h"
21
+ #include "stdlib/complex/float64/reim.h"
22
+ #include <node_api.h>
23
+ #include <assert.h>
24
+ #include <stdbool.h>
25
+
26
+ /**
27
+ * Invokes a unary function accepting and returning double-precision complex floating-point numbers.
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
+ *
35
+ * @param env environment under which the function is invoked
36
+ * @param info callback data
37
+ * @param fcn unary function
38
+ * @return function return value as a Node-API complex-like object
39
+ */
40
+ napi_value stdlib_math_base_napi_z_z( napi_env env, napi_callback_info info, stdlib_complex128_t (*fcn)( stdlib_complex128_t ) ) {
41
+ napi_status status;
42
+
43
+ size_t argc = 1;
44
+ napi_value argv[ 1 ];
45
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
46
+ assert( status == napi_ok );
47
+
48
+ if ( argc < 1 ) {
49
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide a complex number." );
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. 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. 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. 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. Argument must have an imaginary component which a number." );
93
+ assert( status == napi_ok );
94
+ return NULL;
95
+ }
96
+
97
+ double re0;
98
+ status = napi_get_value_double( env, xre, &re0 );
99
+ assert( status == napi_ok );
100
+
101
+ double im0;
102
+ status = napi_get_value_double( env, xim, &im0 );
103
+ assert( status == napi_ok );
104
+
105
+ stdlib_complex128_t v = fcn( stdlib_complex128( re0, im0 ) );
106
+ double re;
107
+ double im;
108
+ stdlib_complex128_reim( v, &re, &im );
109
+
110
+ napi_value obj;
111
+ status = napi_create_object( env, &obj );
112
+ assert( status == napi_ok );
113
+
114
+ napi_value vre;
115
+ status = napi_create_double( env, re, &vre );
116
+ assert( status == napi_ok );
117
+
118
+ status = napi_set_named_property( env, obj, "re", vre );
119
+ assert( status == napi_ok );
120
+
121
+ napi_value vim;
122
+ status = napi_create_double( env, im, &vim );
123
+ assert( status == napi_ok );
124
+
125
+ status = napi_set_named_property( env, obj, "im", vim );
126
+ assert( status == napi_ok );
127
+
128
+ return obj;
129
+ }