@stdlib/math-base-napi-binary 0.3.0 → 0.3.2

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 +5 -10
  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/src/dd_d.c ADDED
@@ -0,0 +1,83 @@
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/dd_d.h"
20
+ #include <node_api.h>
21
+ #include <assert.h>
22
+
23
+ /**
24
+ * Invokes a binary function accepting and returning double-precision floating-point numbers.
25
+ *
26
+ * ## Notes
27
+ *
28
+ * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
29
+ *
30
+ * - `x`: input value.
31
+ * - `y`: input value.
32
+ *
33
+ * @param env environment under which the function is invoked
34
+ * @param info callback data
35
+ * @param fcn binary function
36
+ * @return function return value as a Node-API double-precision floating-point number
37
+ */
38
+ napi_value stdlib_math_base_napi_dd_d( napi_env env, napi_callback_info info, double (*fcn)( double, double ) ) {
39
+ napi_status status;
40
+
41
+ size_t argc = 2;
42
+ napi_value argv[ 2 ];
43
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
44
+ assert( status == napi_ok );
45
+
46
+ if ( argc < 2 ) {
47
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide two numbers." );
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. First argument must be a number." );
57
+ assert( status == napi_ok );
58
+ return NULL;
59
+ }
60
+
61
+ napi_valuetype vtype1;
62
+ status = napi_typeof( env, argv[ 1 ], &vtype1 );
63
+ assert( status == napi_ok );
64
+ if ( vtype1 != napi_number ) {
65
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
66
+ assert( status == napi_ok );
67
+ return NULL;
68
+ }
69
+
70
+ double x;
71
+ status = napi_get_value_double( env, argv[ 0 ], &x );
72
+ assert( status == napi_ok );
73
+
74
+ double y;
75
+ status = napi_get_value_double( env, argv[ 1 ], &y );
76
+ assert( status == napi_ok );
77
+
78
+ napi_value v;
79
+ status = napi_create_double( env, fcn( x, y ), &v );
80
+ assert( status == napi_ok );
81
+
82
+ return v;
83
+ }
package/src/di_d.c ADDED
@@ -0,0 +1,84 @@
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/di_d.h"
20
+ #include <node_api.h>
21
+ #include <stdint.h>
22
+ #include <assert.h>
23
+
24
+ /**
25
+ * 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.
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 double-precision floating-point number
38
+ */
39
+ napi_value stdlib_math_base_napi_di_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_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
+ double x;
72
+ status = napi_get_value_double( 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_double( env, fcn( x, y ), &v );
81
+ assert( status == napi_ok );
82
+
83
+ return v;
84
+ }
package/src/dz_z.c ADDED
@@ -0,0 +1,142 @@
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/dz_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
+
25
+ /**
26
+ * Invokes a binary function accepting a double-precision floating-point number and a double-precision complex floating-point number and returning a double-precision complex 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
+ * - `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_dz_z( napi_env env, napi_callback_info info, stdlib_complex128_t (*fcn)( double, stdlib_complex128_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 arguments." );
50
+ assert( status == napi_ok );
51
+ return NULL;
52
+ }
53
+
54
+ napi_valuetype vtype0;
55
+ status = napi_typeof( env, argv[ 0 ], &vtype0 );
56
+ assert( status == napi_ok );
57
+ if ( vtype0 != napi_number ) {
58
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
59
+ assert( status == napi_ok );
60
+ return NULL;
61
+ }
62
+
63
+ bool hprop;
64
+ status = napi_has_named_property( env, argv[ 1 ], "re", &hprop );
65
+ assert( status == napi_ok );
66
+ if ( !hprop ) {
67
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have a real component." );
68
+ assert( status == napi_ok );
69
+ return NULL;
70
+ }
71
+
72
+ napi_value xre;
73
+ status = napi_get_named_property( env, argv[ 1 ], "re", &xre );
74
+ assert( status == napi_ok );
75
+
76
+ napi_valuetype xretype;
77
+ status = napi_typeof( env, xre, &xretype );
78
+ assert( status == napi_ok );
79
+ if ( xretype != napi_number ) {
80
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have a real component which is a number." );
81
+ assert( status == napi_ok );
82
+ return NULL;
83
+ }
84
+
85
+ status = napi_has_named_property( env, argv[ 1 ], "im", &hprop );
86
+ assert( status == napi_ok );
87
+ if ( !hprop ) {
88
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have an imaginary component." );
89
+ assert( status == napi_ok );
90
+ return NULL;
91
+ }
92
+
93
+ napi_value xim;
94
+ status = napi_get_named_property( env, argv[ 1 ], "im", &xim );
95
+ assert( status == napi_ok );
96
+
97
+ napi_valuetype ximtype;
98
+ status = napi_typeof( env, xim, &ximtype );
99
+ assert( status == napi_ok );
100
+ if ( ximtype != napi_number ) {
101
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have an imaginary component which a number." );
102
+ assert( status == napi_ok );
103
+ return NULL;
104
+ }
105
+
106
+ double y;
107
+ status = napi_get_value_double( env, argv[ 0 ], &y );
108
+ assert( status == napi_ok );
109
+
110
+ double re0;
111
+ status = napi_get_value_double( env, xre, &re0 );
112
+ assert( status == napi_ok );
113
+
114
+ double im0;
115
+ status = napi_get_value_double( env, xim, &im0 );
116
+ assert( status == napi_ok );
117
+
118
+ stdlib_complex128_t v = fcn( y, stdlib_complex128( re0, im0 ) );
119
+ double re;
120
+ double im;
121
+ stdlib_complex128_reim( v, &re, &im );
122
+
123
+ napi_value obj;
124
+ status = napi_create_object( env, &obj );
125
+ assert( status == napi_ok );
126
+
127
+ napi_value vre;
128
+ status = napi_create_double( env, re, &vre );
129
+ assert( status == napi_ok );
130
+
131
+ status = napi_set_named_property( env, obj, "re", vre );
132
+ assert( status == napi_ok );
133
+
134
+ napi_value vim;
135
+ status = napi_create_double( env, im, &vim );
136
+ assert( status == napi_ok );
137
+
138
+ status = napi_set_named_property( env, obj, "im", vim );
139
+ assert( status == napi_ok );
140
+
141
+ return obj;
142
+ }
package/src/fc_c.c ADDED
@@ -0,0 +1,142 @@
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/fc_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 a single-precision floating-point number and a single-precision complex floating-point number and returning a single-precision complex 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
+ * - `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_fc_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( float, 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 arguments." );
50
+ assert( status == napi_ok );
51
+ return NULL;
52
+ }
53
+
54
+ napi_valuetype vtype0;
55
+ status = napi_typeof( env, argv[ 0 ], &vtype0 );
56
+ assert( status == napi_ok );
57
+ if ( vtype0 != napi_number ) {
58
+ status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
59
+ assert( status == napi_ok );
60
+ return NULL;
61
+ }
62
+
63
+ bool hprop;
64
+ status = napi_has_named_property( env, argv[ 1 ], "re", &hprop );
65
+ assert( status == napi_ok );
66
+ if ( !hprop ) {
67
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have a real component." );
68
+ assert( status == napi_ok );
69
+ return NULL;
70
+ }
71
+
72
+ napi_value xre;
73
+ status = napi_get_named_property( env, argv[ 1 ], "re", &xre );
74
+ assert( status == napi_ok );
75
+
76
+ napi_valuetype xretype;
77
+ status = napi_typeof( env, xre, &xretype );
78
+ assert( status == napi_ok );
79
+ if ( xretype != napi_number ) {
80
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have a real component which is a number." );
81
+ assert( status == napi_ok );
82
+ return NULL;
83
+ }
84
+
85
+ status = napi_has_named_property( env, argv[ 1 ], "im", &hprop );
86
+ assert( status == napi_ok );
87
+ if ( !hprop ) {
88
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have an imaginary component." );
89
+ assert( status == napi_ok );
90
+ return NULL;
91
+ }
92
+
93
+ napi_value xim;
94
+ status = napi_get_named_property( env, argv[ 1 ], "im", &xim );
95
+ assert( status == napi_ok );
96
+
97
+ napi_valuetype ximtype;
98
+ status = napi_typeof( env, xim, &ximtype );
99
+ assert( status == napi_ok );
100
+ if ( ximtype != napi_number ) {
101
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must have an imaginary component which a number." );
102
+ assert( status == napi_ok );
103
+ return NULL;
104
+ }
105
+
106
+ double y;
107
+ status = napi_get_value_double( env, argv[ 0 ], &y );
108
+ assert( status == napi_ok );
109
+
110
+ double re0;
111
+ status = napi_get_value_double( env, xre, &re0 );
112
+ assert( status == napi_ok );
113
+
114
+ double im0;
115
+ status = napi_get_value_double( env, xim, &im0 );
116
+ assert( status == napi_ok );
117
+
118
+ stdlib_complex64_t v = fcn( y, stdlib_complex64( (float)re0, (float)im0 ) );
119
+ float re;
120
+ float im;
121
+ stdlib_complex64_reim( v, &re, &im );
122
+
123
+ napi_value obj;
124
+ status = napi_create_object( env, &obj );
125
+ assert( status == napi_ok );
126
+
127
+ napi_value vre;
128
+ status = napi_create_double( env, (double)re, &vre );
129
+ assert( status == napi_ok );
130
+
131
+ status = napi_set_named_property( env, obj, "re", vre );
132
+ assert( status == napi_ok );
133
+
134
+ napi_value vim;
135
+ status = napi_create_double( env, (double)im, &vim );
136
+ assert( status == napi_ok );
137
+
138
+ status = napi_set_named_property( env, obj, "im", vim );
139
+ assert( status == napi_ok );
140
+
141
+ return obj;
142
+ }
package/src/ff_f.c ADDED
@@ -0,0 +1,83 @@
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/ff_f.h"
20
+ #include <node_api.h>
21
+ #include <assert.h>
22
+
23
+ /**
24
+ * Invokes a binary function accepting and returning single-precision floating-point numbers.
25
+ *
26
+ * ## Notes
27
+ *
28
+ * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
29
+ *
30
+ * - `x`: input value.
31
+ * - `y`: input value.
32
+ *
33
+ * @param env environment under which the function is invoked
34
+ * @param info callback data
35
+ * @param fcn binary function
36
+ * @return function return value as a Node-API double-precision floating-point number
37
+ */
38
+ napi_value stdlib_math_base_napi_ff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float ) ) {
39
+ napi_status status;
40
+
41
+ size_t argc = 2;
42
+ napi_value argv[ 2 ];
43
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
44
+ assert( status == napi_ok );
45
+
46
+ if ( argc < 2 ) {
47
+ status = napi_throw_error( env, NULL, "invalid invocation. Must provide two numbers." );
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. First argument must be a number." );
57
+ assert( status == napi_ok );
58
+ return NULL;
59
+ }
60
+
61
+ napi_valuetype vtype1;
62
+ status = napi_typeof( env, argv[ 1 ], &vtype1 );
63
+ assert( status == napi_ok );
64
+ if ( vtype1 != napi_number ) {
65
+ status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
66
+ assert( status == napi_ok );
67
+ return NULL;
68
+ }
69
+
70
+ double x;
71
+ status = napi_get_value_double( env, argv[ 0 ], &x );
72
+ assert( status == napi_ok );
73
+
74
+ double y;
75
+ status = napi_get_value_double( env, argv[ 1 ], &y );
76
+ assert( status == napi_ok );
77
+
78
+ napi_value v;
79
+ status = napi_create_double( env, (double)fcn( (float)x, (float)y ), &v );
80
+ assert( status == napi_ok );
81
+
82
+ return v;
83
+ }
package/src/fi_f.c ADDED
@@ -0,0 +1,84 @@
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/fi_f.h"
20
+ #include <node_api.h>
21
+ #include <stdint.h>
22
+ #include <assert.h>
23
+
24
+ /**
25
+ * 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.
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 double-precision floating-point number
38
+ */
39
+ napi_value stdlib_math_base_napi_fi_f( napi_env env, napi_callback_info info, float (*fcn)( float, int32_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
+ double x;
72
+ status = napi_get_value_double( 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_double( env, (double)fcn( (float)x, y ), &v );
81
+ assert( status == napi_ok );
82
+
83
+ return v;
84
+ }
package/src/id_d.c ADDED
@@ -0,0 +1,84 @@
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/id_d.h"
20
+ #include <node_api.h>
21
+ #include <stdint.h>
22
+ #include <assert.h>
23
+
24
+ /**
25
+ * Invokes a binary function accepting a signed 32-bit integer and a double-precision floating-point number and returning a double-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
+ * - `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 double-precision floating-point number
38
+ */
39
+ napi_value stdlib_math_base_napi_id_d( napi_env env, napi_callback_info info, double (*fcn)( int32_t, double ) ) {
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
+ double y;
76
+ status = napi_get_value_double( env, argv[ 1 ], &y );
77
+ assert( status == napi_ok );
78
+
79
+ napi_value v;
80
+ status = napi_create_double( env, fcn( x, y ), &v );
81
+ assert( status == napi_ok );
82
+
83
+ return v;
84
+ }