@stdlib/math-base-napi-ternary 0.3.0 → 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/src/main.c DELETED
@@ -1,250 +0,0 @@
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/ternary.h"
20
- #include <node_api.h>
21
- #include <stdint.h>
22
- #include <assert.h>
23
-
24
- /**
25
- * Invokes a ternary function accepting and returning double-precision floating-point numbers.
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
- * - `z`: input value.
34
- *
35
- * @param env environment under which the function is invoked
36
- * @param info callback data
37
- * @param fcn ternary function
38
- * @return function return value as a Node-API double-precision floating-point number
39
- */
40
- napi_value stdlib_math_base_napi_ddd_d( napi_env env, napi_callback_info info, double (*fcn)( double, double, double ) ) {
41
- napi_status status;
42
-
43
- size_t argc = 3;
44
- napi_value argv[ 3 ];
45
- status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
46
- assert( status == napi_ok );
47
-
48
- if ( argc < 3 ) {
49
- status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." );
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
- napi_valuetype vtype1;
64
- status = napi_typeof( env, argv[ 1 ], &vtype1 );
65
- assert( status == napi_ok );
66
- if ( vtype1 != napi_number ) {
67
- status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
68
- assert( status == napi_ok );
69
- return NULL;
70
- }
71
-
72
- napi_valuetype vtype2;
73
- status = napi_typeof( env, argv[ 2 ], &vtype2 );
74
- assert( status == napi_ok );
75
- if ( vtype2 != napi_number ) {
76
- status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." );
77
- assert( status == napi_ok );
78
- return NULL;
79
- }
80
-
81
- double x;
82
- status = napi_get_value_double( env, argv[ 0 ], &x );
83
- assert( status == napi_ok );
84
-
85
- double y;
86
- status = napi_get_value_double( env, argv[ 1 ], &y );
87
- assert( status == napi_ok );
88
-
89
- double z;
90
- status = napi_get_value_double( env, argv[ 2 ], &z );
91
- assert( status == napi_ok );
92
-
93
- napi_value v;
94
- status = napi_create_double( env, fcn( x, y, z ), &v );
95
- assert( status == napi_ok );
96
-
97
- return v;
98
- }
99
-
100
- /**
101
- * Invokes a ternary function accepting and returning single-precision floating-point numbers.
102
- *
103
- * ## Notes
104
- *
105
- * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
106
- *
107
- * - `x`: input value.
108
- * - `y`: input value.
109
- * - `z`: input value.
110
- *
111
- * @param env environment under which the function is invoked
112
- * @param info callback data
113
- * @param fcn ternary function
114
- * @return function return value as a Node-API double-precision floating-point number
115
- */
116
- napi_value stdlib_math_base_napi_fff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float, float ) ) {
117
- napi_status status;
118
-
119
- size_t argc = 3;
120
- napi_value argv[ 3 ];
121
- status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
122
- assert( status == napi_ok );
123
-
124
- if ( argc < 3 ) {
125
- status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." );
126
- assert( status == napi_ok );
127
- return NULL;
128
- }
129
-
130
- napi_valuetype vtype0;
131
- status = napi_typeof( env, argv[ 0 ], &vtype0 );
132
- assert( status == napi_ok );
133
- if ( vtype0 != napi_number ) {
134
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
135
- assert( status == napi_ok );
136
- return NULL;
137
- }
138
-
139
- napi_valuetype vtype1;
140
- status = napi_typeof( env, argv[ 1 ], &vtype1 );
141
- assert( status == napi_ok );
142
- if ( vtype1 != napi_number ) {
143
- status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
144
- assert( status == napi_ok );
145
- return NULL;
146
- }
147
-
148
- napi_valuetype vtype2;
149
- status = napi_typeof( env, argv[ 2 ], &vtype2 );
150
- assert( status == napi_ok );
151
- if ( vtype2 != napi_number ) {
152
- status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." );
153
- assert( status == napi_ok );
154
- return NULL;
155
- }
156
-
157
- double x;
158
- status = napi_get_value_double( env, argv[ 0 ], &x );
159
- assert( status == napi_ok );
160
-
161
- double y;
162
- status = napi_get_value_double( env, argv[ 1 ], &y );
163
- assert( status == napi_ok );
164
-
165
- double z;
166
- status = napi_get_value_double( env, argv[ 2 ], &z );
167
- assert( status == napi_ok );
168
-
169
- napi_value v;
170
- status = napi_create_double( env, (double)fcn( (float)x, (float)y, (float)z ), &v );
171
- assert( status == napi_ok );
172
-
173
- return v;
174
- }
175
-
176
- /**
177
- * Invokes a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number.
178
- *
179
- * ## Notes
180
- *
181
- * - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
182
- *
183
- * - `x`: input value.
184
- * - `y`: input value.
185
- * - `z`: input value.
186
- *
187
- * @param env environment under which the function is invoked
188
- * @param info callback data
189
- * @param fcn ternary function
190
- * @return function return value as a Node-API double-precision floating-point number
191
- */
192
- napi_value stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) ) {
193
- napi_status status;
194
-
195
- size_t argc = 3;
196
- napi_value argv[ 3 ];
197
- status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
198
- assert( status == napi_ok );
199
-
200
- if ( argc < 3 ) {
201
- status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." );
202
- assert( status == napi_ok );
203
- return NULL;
204
- }
205
-
206
- napi_valuetype vtype0;
207
- status = napi_typeof( env, argv[ 0 ], &vtype0 );
208
- assert( status == napi_ok );
209
- if ( vtype0 != napi_number ) {
210
- status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
211
- assert( status == napi_ok );
212
- return NULL;
213
- }
214
-
215
- napi_valuetype vtype1;
216
- status = napi_typeof( env, argv[ 1 ], &vtype1 );
217
- assert( status == napi_ok );
218
- if ( vtype1 != napi_number ) {
219
- status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
220
- assert( status == napi_ok );
221
- return NULL;
222
- }
223
-
224
- napi_valuetype vtype2;
225
- status = napi_typeof( env, argv[ 2 ], &vtype2 );
226
- assert( status == napi_ok );
227
- if ( vtype2 != napi_number ) {
228
- status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." );
229
- assert( status == napi_ok );
230
- return NULL;
231
- }
232
-
233
- double x;
234
- status = napi_get_value_double( env, argv[ 0 ], &x );
235
- assert( status == napi_ok );
236
-
237
- int32_t y;
238
- status = napi_get_value_int32( env, argv[ 1 ], &y );
239
- assert( status == napi_ok );
240
-
241
- int32_t z;
242
- status = napi_get_value_int32( env, argv[ 2 ], &z );
243
- assert( status == napi_ok );
244
-
245
- napi_value v;
246
- status = napi_create_double( env, fcn( x, y, z ), &v );
247
- assert( status == napi_ok );
248
-
249
- return v;
250
- }