@stdlib/math-base-napi-unary 0.2.3 → 0.2.5
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.
- package/NOTICE +1 -1
- package/README.md +710 -144
- package/include/stdlib/math/base/napi/unary/b_b.h +84 -0
- package/include/stdlib/math/base/napi/unary/c_c.h +93 -0
- package/include/stdlib/math/base/napi/unary/c_f.h +84 -0
- package/include/stdlib/math/base/napi/unary/d_d.h +81 -0
- package/include/stdlib/math/base/napi/unary/d_f.h +81 -0
- package/include/stdlib/math/base/napi/unary/f_f.h +81 -0
- package/include/stdlib/math/base/napi/unary/f_i.h +84 -0
- package/include/stdlib/math/base/napi/unary/h_h.h +84 -0
- package/include/stdlib/math/base/napi/unary/i_d.h +84 -0
- package/include/stdlib/math/base/napi/unary/i_f.h +84 -0
- package/include/stdlib/math/base/napi/unary/i_i.h +84 -0
- package/include/stdlib/math/base/napi/unary/k_k.h +84 -0
- package/include/stdlib/math/base/napi/unary/s_s.h +84 -0
- package/include/stdlib/math/base/napi/unary/t_t.h +84 -0
- package/include/stdlib/math/base/napi/unary/u_u.h +84 -0
- package/include/stdlib/math/base/napi/unary/z_d.h +84 -0
- package/include/stdlib/math/base/napi/unary/z_z.h +93 -0
- package/include/stdlib/math/base/napi/unary.h +18 -406
- package/manifest.json +56 -37
- package/package.json +8 -10
- package/src/b_b.c +71 -0
- package/src/c_c.c +129 -0
- package/src/c_f.c +109 -0
- package/src/d_d.c +69 -0
- package/src/d_f.c +69 -0
- package/src/f_f.c +69 -0
- package/src/f_i.c +70 -0
- package/src/h_h.c +74 -0
- package/src/i_d.c +70 -0
- package/src/i_f.c +70 -0
- package/src/i_i.c +70 -0
- package/src/k_k.c +70 -0
- package/src/s_s.c +71 -0
- package/src/t_t.c +70 -0
- package/src/u_u.c +70 -0
- package/src/z_d.c +109 -0
- package/src/z_z.c +129 -0
- package/src/main.c +0 -601
package/src/b_b.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/b_b.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 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 unsigned 32-bit integer
|
|
37
|
+
*/
|
|
38
|
+
napi_value stdlib_math_base_napi_b_b( napi_env env, napi_callback_info info, uint8_t (*fcn)( uint8_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( (uint8_t)x ), &v );
|
|
67
|
+
assert( status == napi_ok );
|
|
68
|
+
|
|
69
|
+
return v;
|
|
70
|
+
}
|
|
71
|
+
|
package/src/c_c.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/c_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
|
+
#include <stdbool.h>
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Invokes a unary function accepting and returning single-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_c_c( napi_env env, napi_callback_info info, stdlib_complex64_t (*fcn)( stdlib_complex64_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_complex64_t v = fcn( stdlib_complex64( (float)re0, (float)im0 ) );
|
|
106
|
+
float re;
|
|
107
|
+
float im;
|
|
108
|
+
stdlib_complex64_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, (double)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, (double)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
|
+
}
|
package/src/c_f.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/c_f.h"
|
|
20
|
+
#include "stdlib/complex/float32/ctor.h"
|
|
21
|
+
#include <node_api.h>
|
|
22
|
+
#include <assert.h>
|
|
23
|
+
#include <stdbool.h>
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Invokes a unary function accepting a single-precision complex floating-point number and returning a single-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_c_f( napi_env env, napi_callback_info info, float (*fcn)( stdlib_complex64_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, (double)fcn( stdlib_complex64( (float)re, (float)im ) ), &v );
|
|
106
|
+
assert( status == napi_ok );
|
|
107
|
+
|
|
108
|
+
return v;
|
|
109
|
+
}
|
package/src/d_d.c
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
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/d_d.h"
|
|
20
|
+
#include <node_api.h>
|
|
21
|
+
#include <assert.h>
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Invokes a unary 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
|
+
*
|
|
32
|
+
* @param env environment under which the function is invoked
|
|
33
|
+
* @param info callback data
|
|
34
|
+
* @param fcn unary function
|
|
35
|
+
* @return function return value as a Node-API double-precision floating-point number
|
|
36
|
+
*/
|
|
37
|
+
napi_value stdlib_math_base_napi_d_d( napi_env env, napi_callback_info info, double (*fcn)( double ) ) {
|
|
38
|
+
napi_status status;
|
|
39
|
+
|
|
40
|
+
size_t argc = 1;
|
|
41
|
+
napi_value argv[ 1 ];
|
|
42
|
+
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
|
|
43
|
+
assert( status == napi_ok );
|
|
44
|
+
|
|
45
|
+
if ( argc < 1 ) {
|
|
46
|
+
status = napi_throw_error( env, NULL, "invalid invocation. Must provide a number." );
|
|
47
|
+
assert( status == napi_ok );
|
|
48
|
+
return NULL;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
napi_valuetype vtype0;
|
|
52
|
+
status = napi_typeof( env, argv[ 0 ], &vtype0 );
|
|
53
|
+
assert( status == napi_ok );
|
|
54
|
+
if ( vtype0 != napi_number ) {
|
|
55
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Must provide a number." );
|
|
56
|
+
assert( status == napi_ok );
|
|
57
|
+
return NULL;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
double x;
|
|
61
|
+
status = napi_get_value_double( env, argv[ 0 ], &x );
|
|
62
|
+
assert( status == napi_ok );
|
|
63
|
+
|
|
64
|
+
napi_value v;
|
|
65
|
+
status = napi_create_double( env, fcn( x ), &v );
|
|
66
|
+
assert( status == napi_ok );
|
|
67
|
+
|
|
68
|
+
return v;
|
|
69
|
+
}
|
package/src/d_f.c
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
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/d_f.h"
|
|
20
|
+
#include <node_api.h>
|
|
21
|
+
#include <assert.h>
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Invokes a unary function accepting a double-precision floating-point number and returning a single-precision floating-point number.
|
|
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
|
+
*
|
|
32
|
+
* @param env environment under which the function is invoked
|
|
33
|
+
* @param info callback data
|
|
34
|
+
* @param fcn unary function
|
|
35
|
+
* @return function return value as a Node-API double-precision floating-point number
|
|
36
|
+
*/
|
|
37
|
+
napi_value stdlib_math_base_napi_d_f( napi_env env, napi_callback_info info, float (*fcn)( double ) ) {
|
|
38
|
+
napi_status status;
|
|
39
|
+
|
|
40
|
+
size_t argc = 1;
|
|
41
|
+
napi_value argv[ 1 ];
|
|
42
|
+
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
|
|
43
|
+
assert( status == napi_ok );
|
|
44
|
+
|
|
45
|
+
if ( argc < 1 ) {
|
|
46
|
+
status = napi_throw_error( env, NULL, "invalid invocation. Must provide a number." );
|
|
47
|
+
assert( status == napi_ok );
|
|
48
|
+
return NULL;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
napi_valuetype vtype0;
|
|
52
|
+
status = napi_typeof( env, argv[ 0 ], &vtype0 );
|
|
53
|
+
assert( status == napi_ok );
|
|
54
|
+
if ( vtype0 != napi_number ) {
|
|
55
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Must provide a number." );
|
|
56
|
+
assert( status == napi_ok );
|
|
57
|
+
return NULL;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
double x;
|
|
61
|
+
status = napi_get_value_double( env, argv[ 0 ], &x );
|
|
62
|
+
assert( status == napi_ok );
|
|
63
|
+
|
|
64
|
+
napi_value v;
|
|
65
|
+
status = napi_create_double( env, (double)fcn( x ), &v );
|
|
66
|
+
assert( status == napi_ok );
|
|
67
|
+
|
|
68
|
+
return v;
|
|
69
|
+
}
|
package/src/f_f.c
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
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/f_f.h"
|
|
20
|
+
#include <node_api.h>
|
|
21
|
+
#include <assert.h>
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Invokes a unary 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
|
+
*
|
|
32
|
+
* @param env environment under which the function is invoked
|
|
33
|
+
* @param info callback data
|
|
34
|
+
* @param fcn unary function
|
|
35
|
+
* @return function return value as a Node-API double-precision floating-point number
|
|
36
|
+
*/
|
|
37
|
+
napi_value stdlib_math_base_napi_f_f( napi_env env, napi_callback_info info, float (*fcn)( float ) ) {
|
|
38
|
+
napi_status status;
|
|
39
|
+
|
|
40
|
+
size_t argc = 1;
|
|
41
|
+
napi_value argv[ 1 ];
|
|
42
|
+
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
|
|
43
|
+
assert( status == napi_ok );
|
|
44
|
+
|
|
45
|
+
if ( argc < 1 ) {
|
|
46
|
+
status = napi_throw_error( env, NULL, "invalid invocation. Must provide a number." );
|
|
47
|
+
assert( status == napi_ok );
|
|
48
|
+
return NULL;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
napi_valuetype vtype0;
|
|
52
|
+
status = napi_typeof( env, argv[ 0 ], &vtype0 );
|
|
53
|
+
assert( status == napi_ok );
|
|
54
|
+
if ( vtype0 != napi_number ) {
|
|
55
|
+
status = napi_throw_type_error( env, NULL, "invalid argument. Must provide a number." );
|
|
56
|
+
assert( status == napi_ok );
|
|
57
|
+
return NULL;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
double x;
|
|
61
|
+
status = napi_get_value_double( env, argv[ 0 ], &x );
|
|
62
|
+
assert( status == napi_ok );
|
|
63
|
+
|
|
64
|
+
napi_value v;
|
|
65
|
+
status = napi_create_double( env, (double)fcn( (float)x ), &v );
|
|
66
|
+
assert( status == napi_ok );
|
|
67
|
+
|
|
68
|
+
return v;
|
|
69
|
+
}
|
package/src/f_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/f_i.h"
|
|
20
|
+
#include <node_api.h>
|
|
21
|
+
#include <assert.h>
|
|
22
|
+
#include <stdint.h>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Invokes a unary function accepting a single-precision floating-point number and returning a signed 32-bit integer.
|
|
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_f_i( napi_env env, napi_callback_info info, int32_t (*fcn)( float ) ) {
|
|
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
|
+
double x;
|
|
62
|
+
status = napi_get_value_double( env, argv[ 0 ], &x );
|
|
63
|
+
assert( status == napi_ok );
|
|
64
|
+
|
|
65
|
+
napi_value v;
|
|
66
|
+
status = napi_create_int32( env, (int32_t)fcn( (float)x ), &v );
|
|
67
|
+
assert( status == napi_ok );
|
|
68
|
+
|
|
69
|
+
return v;
|
|
70
|
+
}
|
package/src/h_h.c
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2026 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/h_h.h"
|
|
20
|
+
#include "stdlib/number/float64/base/to_float16.h"
|
|
21
|
+
#include "stdlib/number/float16/base/to_float64.h"
|
|
22
|
+
#include "stdlib/number/float16/ctor.h"
|
|
23
|
+
#include <node_api.h>
|
|
24
|
+
#include <assert.h>
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Invokes a unary function accepting and returning half-precision 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 half-precision floating-point number
|
|
39
|
+
*/
|
|
40
|
+
napi_value stdlib_math_base_napi_h_h( napi_env env, napi_callback_info info, stdlib_float16_t (*fcn)( stdlib_float16_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 number." );
|
|
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. Must provide a number." );
|
|
59
|
+
assert( status == napi_ok );
|
|
60
|
+
return NULL;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
double x;
|
|
64
|
+
status = napi_get_value_double( env, argv[ 0 ], &x );
|
|
65
|
+
assert( status == napi_ok );
|
|
66
|
+
|
|
67
|
+
stdlib_float16_t out = fcn( stdlib_base_float64_to_float16( x ) );
|
|
68
|
+
|
|
69
|
+
napi_value v;
|
|
70
|
+
status = napi_create_double( env, stdlib_base_float16_to_float64( out ), &v );
|
|
71
|
+
assert( status == napi_ok );
|
|
72
|
+
|
|
73
|
+
return v;
|
|
74
|
+
}
|