@stdlib/math-base-napi-binary 0.2.1 → 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.
- package/NOTICE +1 -1
- package/README.md +1155 -252
- package/include/stdlib/math/base/napi/binary/bb_b.h +84 -0
- package/include/stdlib/math/base/napi/binary/cc_c.h +98 -0
- package/include/stdlib/math/base/napi/binary/cf_c.h +89 -0
- package/include/stdlib/math/base/napi/binary/ci_c.h +91 -0
- package/include/stdlib/math/base/napi/binary/dd_d.h +81 -0
- package/include/stdlib/math/base/napi/binary/di_d.h +84 -0
- package/include/stdlib/math/base/napi/binary/dz_z.h +89 -0
- package/include/stdlib/math/base/napi/binary/fc_c.h +89 -0
- package/include/stdlib/math/base/napi/binary/ff_f.h +81 -0
- package/include/stdlib/math/base/napi/binary/fi_f.h +84 -0
- package/include/stdlib/math/base/napi/binary/id_d.h +84 -0
- package/include/stdlib/math/base/napi/binary/ii_d.h +84 -0
- package/include/stdlib/math/base/napi/binary/ii_f.h +84 -0
- package/include/stdlib/math/base/napi/binary/ii_i.h +84 -0
- package/include/stdlib/math/base/napi/binary/kk_k.h +84 -0
- package/include/stdlib/math/base/napi/binary/ll_d.h +84 -0
- package/include/stdlib/math/base/napi/binary/ss_s.h +84 -0
- package/include/stdlib/math/base/napi/binary/tt_t.h +84 -0
- package/include/stdlib/math/base/napi/binary/uu_u.h +84 -0
- package/include/stdlib/math/base/napi/binary/zd_z.h +89 -0
- package/include/stdlib/math/base/napi/binary/zi_z.h +91 -0
- package/include/stdlib/math/base/napi/binary/zz_z.h +98 -0
- package/include/stdlib/math/base/napi/binary.h +23 -531
- package/manifest.json +60 -40
- package/package.json +6 -6
- package/src/bb_b.c +84 -0
- package/src/cc_c.c +179 -0
- package/src/cf_c.c +143 -0
- package/src/ci_c.c +143 -0
- package/src/dd_d.c +83 -0
- package/src/di_d.c +84 -0
- package/src/dz_z.c +142 -0
- package/src/fc_c.c +142 -0
- package/src/ff_f.c +83 -0
- package/src/fi_f.c +84 -0
- package/src/id_d.c +84 -0
- package/src/ii_d.c +84 -0
- package/src/ii_f.c +84 -0
- package/src/ii_i.c +84 -0
- package/src/kk_k.c +84 -0
- package/src/ll_d.c +84 -0
- package/src/ss_s.c +84 -0
- package/src/tt_t.c +84 -0
- package/src/uu_u.c +84 -0
- package/src/zd_z.c +142 -0
- package/src/zi_z.c +143 -0
- package/src/zz_z.c +179 -0
- package/include.gypi +0 -53
- package/src/main.c +0 -1063
package/src/ii_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/ii_f.h"
|
|
20
|
+
#include <node_api.h>
|
|
21
|
+
#include <stdint.h>
|
|
22
|
+
#include <assert.h>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Invokes a binary function accepting signed 32-bit integers 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 single-precision floating-point number
|
|
38
|
+
*/
|
|
39
|
+
napi_value stdlib_math_base_napi_ii_f( napi_env env, napi_callback_info info, float (*fcn)( int32_t, 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
|
+
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_double( env, (double)fcn( x, y ), &v );
|
|
81
|
+
assert( status == napi_ok );
|
|
82
|
+
|
|
83
|
+
return v;
|
|
84
|
+
}
|
package/src/ii_i.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/ii_i.h"
|
|
20
|
+
#include <node_api.h>
|
|
21
|
+
#include <stdint.h>
|
|
22
|
+
#include <assert.h>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Invokes a binary 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
|
+
* - `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_ii_i( napi_env env, napi_callback_info info, int32_t (*fcn)( int32_t, 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
|
+
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, fcn( x, y ), &v );
|
|
81
|
+
assert( status == napi_ok );
|
|
82
|
+
|
|
83
|
+
return v;
|
|
84
|
+
}
|
package/src/kk_k.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/kk_k.h"
|
|
20
|
+
#include <node_api.h>
|
|
21
|
+
#include <stdint.h>
|
|
22
|
+
#include <assert.h>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Invokes a binary 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
|
+
* - `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_kk_k( napi_env env, napi_callback_info info, int16_t (*fcn)( int16_t, int16_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( (int16_t)x, (int16_t)y ), &v );
|
|
81
|
+
assert( status == napi_ok );
|
|
82
|
+
|
|
83
|
+
return v;
|
|
84
|
+
}
|
package/src/ll_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/ll_d.h"
|
|
20
|
+
#include <node_api.h>
|
|
21
|
+
#include <stdint.h>
|
|
22
|
+
#include <assert.h>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Invokes a binary function accepting signed 64-bit integers 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_ll_d( napi_env env, napi_callback_info info, double (*fcn)( int64_t, int64_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
|
+
int64_t x;
|
|
72
|
+
status = napi_get_value_int64( env, argv[ 0 ], &x );
|
|
73
|
+
assert( status == napi_ok );
|
|
74
|
+
|
|
75
|
+
int64_t y;
|
|
76
|
+
status = napi_get_value_int64( 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/ss_s.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/ss_s.h"
|
|
20
|
+
#include <node_api.h>
|
|
21
|
+
#include <stdint.h>
|
|
22
|
+
#include <assert.h>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Invokes a binary 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
|
+
* - `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_ss_s( napi_env env, napi_callback_info info, int8_t (*fcn)( int8_t, int8_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( (int8_t)x, (int8_t)y ), &v );
|
|
81
|
+
assert( status == napi_ok );
|
|
82
|
+
|
|
83
|
+
return v;
|
|
84
|
+
}
|
package/src/tt_t.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/tt_t.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 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
|
+
* - `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_tt_t( napi_env env, napi_callback_info info, uint16_t (*fcn)( uint16_t, uint16_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( (uint16_t)x, (uint16_t)y ), &v );
|
|
81
|
+
assert( status == napi_ok );
|
|
82
|
+
|
|
83
|
+
return v;
|
|
84
|
+
}
|
package/src/uu_u.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/uu_u.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 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
|
+
* - `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 unsigned 32-bit integer
|
|
38
|
+
*/
|
|
39
|
+
napi_value stdlib_math_base_napi_uu_u( napi_env env, napi_callback_info info, uint32_t (*fcn)( uint32_t, uint32_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
|
+
uint32_t x;
|
|
72
|
+
status = napi_get_value_uint32( env, argv[ 0 ], &x );
|
|
73
|
+
assert( status == napi_ok );
|
|
74
|
+
|
|
75
|
+
uint32_t y;
|
|
76
|
+
status = napi_get_value_uint32( env, argv[ 1 ], &y );
|
|
77
|
+
assert( status == napi_ok );
|
|
78
|
+
|
|
79
|
+
napi_value v;
|
|
80
|
+
status = napi_create_uint32( env, fcn( x, y ), &v );
|
|
81
|
+
assert( status == napi_ok );
|
|
82
|
+
|
|
83
|
+
return v;
|
|
84
|
+
}
|