@stdlib/math-base-assert-is-nonnegative-finite 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 +110 -5
- package/include/stdlib/math/base/assert/is_nonnegative_finite.h +40 -0
- package/lib/native.js +51 -0
- package/manifest.json +40 -0
- package/package.json +6 -2
- package/src/addon.c +89 -0
- package/src/main.c +37 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -107,10 +107,109 @@ bool = isNonNegativeFinite( NaN );
|
|
|
107
107
|
|
|
108
108
|
<!-- /.examples -->
|
|
109
109
|
|
|
110
|
+
<!-- C interface documentation. -->
|
|
111
|
+
|
|
112
|
+
* * *
|
|
113
|
+
|
|
114
|
+
<section class="c">
|
|
115
|
+
|
|
116
|
+
## C APIs
|
|
117
|
+
|
|
118
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
119
|
+
|
|
120
|
+
<section class="intro">
|
|
121
|
+
|
|
122
|
+
</section>
|
|
123
|
+
|
|
124
|
+
<!-- /.intro -->
|
|
125
|
+
|
|
126
|
+
<!-- C usage documentation. -->
|
|
127
|
+
|
|
128
|
+
<section class="usage">
|
|
129
|
+
|
|
130
|
+
### Usage
|
|
131
|
+
|
|
132
|
+
```c
|
|
133
|
+
#include "stdlib/math/base/assert/is_nonnegative_finite.h"
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### stdlib_base_is_nonnegative_finite( x )
|
|
137
|
+
|
|
138
|
+
Tests if a numeric value is a nonnegative finite number.
|
|
139
|
+
|
|
140
|
+
```c
|
|
141
|
+
#include <stdbool.h>
|
|
142
|
+
|
|
143
|
+
bool out = stdlib_base_is_nonnegative_finite( 3.14 );
|
|
144
|
+
// returns true
|
|
145
|
+
|
|
146
|
+
out = stdlib_base_is_nonnegative_finite( -2.0 );
|
|
147
|
+
// returns false
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The function accepts the following arguments:
|
|
151
|
+
|
|
152
|
+
- **x**: `[in] double` input value.
|
|
153
|
+
|
|
154
|
+
```c
|
|
155
|
+
bool stdlib_base_is_nonnegative_finite( const double x );
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
</section>
|
|
159
|
+
|
|
160
|
+
<!-- /.usage -->
|
|
161
|
+
|
|
162
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
163
|
+
|
|
164
|
+
<section class="notes">
|
|
165
|
+
|
|
166
|
+
</section>
|
|
167
|
+
|
|
168
|
+
<!-- /.notes -->
|
|
169
|
+
|
|
170
|
+
<!-- C API usage examples. -->
|
|
171
|
+
|
|
172
|
+
<section class="examples">
|
|
173
|
+
|
|
174
|
+
### Examples
|
|
175
|
+
|
|
176
|
+
```c
|
|
177
|
+
#include "stdlib/math/base/assert/is_nonnegative_finite.h"
|
|
178
|
+
#include <stdio.h>
|
|
179
|
+
#include <stdbool.h>
|
|
180
|
+
|
|
181
|
+
int main( void ) {
|
|
182
|
+
const double x[] = { 5.0, -5.0, 3.14, -3.14, 0.0, 0.0/0.0 };
|
|
183
|
+
|
|
184
|
+
bool b;
|
|
185
|
+
int i;
|
|
186
|
+
for ( i = 0; i < 6; i++ ) {
|
|
187
|
+
b = stdlib_base_is_nonnegative_finite( x[ i ] );
|
|
188
|
+
printf( "Value: %lf. Is nonnegative finite? %s.\n", x[ i ], ( b ) ? "True" : "False" );
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
</section>
|
|
194
|
+
|
|
195
|
+
<!-- /.examples -->
|
|
196
|
+
|
|
197
|
+
</section>
|
|
198
|
+
|
|
199
|
+
<!-- /.c -->
|
|
200
|
+
|
|
110
201
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
111
202
|
|
|
112
203
|
<section class="related">
|
|
113
204
|
|
|
205
|
+
* * *
|
|
206
|
+
|
|
207
|
+
## See Also
|
|
208
|
+
|
|
209
|
+
- <span class="package-name">[`@stdlib/math-base/assert/is-negative-finite`][@stdlib/math/base/assert/is-negative-finite]</span><span class="delimiter">: </span><span class="description">test if a double-precision floating-point numeric value is a negative finite number.</span>
|
|
210
|
+
- <span class="package-name">[`@stdlib/math-base/assert/is-positive-finite`][@stdlib/math/base/assert/is-positive-finite]</span><span class="delimiter">: </span><span class="description">test if a double-precision floating-point numeric value is a positive finite number.</span>
|
|
211
|
+
- <span class="package-name">[`@stdlib/math-base/assert/is-nonpositive-finite`][@stdlib/math/base/assert/is-nonpositive-finite]</span><span class="delimiter">: </span><span class="description">test if a numeric value is a nonpositive finite number.</span>
|
|
212
|
+
|
|
114
213
|
</section>
|
|
115
214
|
|
|
116
215
|
<!-- /.related -->
|
|
@@ -141,7 +240,7 @@ See [LICENSE][stdlib-license].
|
|
|
141
240
|
|
|
142
241
|
## Copyright
|
|
143
242
|
|
|
144
|
-
Copyright © 2016-
|
|
243
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
145
244
|
|
|
146
245
|
</section>
|
|
147
246
|
|
|
@@ -154,8 +253,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
154
253
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-assert-is-nonnegative-finite.svg
|
|
155
254
|
[npm-url]: https://npmjs.org/package/@stdlib/math-base-assert-is-nonnegative-finite
|
|
156
255
|
|
|
157
|
-
[test-image]: https://github.com/stdlib-js/math-base-assert-is-nonnegative-finite/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
158
|
-
[test-url]: https://github.com/stdlib-js/math-base-assert-is-nonnegative-finite/actions/workflows/test.yml?query=branch:v0.
|
|
256
|
+
[test-image]: https://github.com/stdlib-js/math-base-assert-is-nonnegative-finite/actions/workflows/test.yml/badge.svg?branch=v0.3.1
|
|
257
|
+
[test-url]: https://github.com/stdlib-js/math-base-assert-is-nonnegative-finite/actions/workflows/test.yml?query=branch:v0.3.1
|
|
159
258
|
|
|
160
259
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-assert-is-nonnegative-finite/main.svg
|
|
161
260
|
[coverage-url]: https://codecov.io/github/stdlib-js/math-base-assert-is-nonnegative-finite?branch=main
|
|
@@ -167,8 +266,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
167
266
|
|
|
168
267
|
-->
|
|
169
268
|
|
|
170
|
-
[chat-image]: https://img.shields.io/
|
|
171
|
-
[chat-url]: https://
|
|
269
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
270
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
172
271
|
|
|
173
272
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
174
273
|
|
|
@@ -189,6 +288,12 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
189
288
|
|
|
190
289
|
<!-- <related-links> -->
|
|
191
290
|
|
|
291
|
+
[@stdlib/math/base/assert/is-negative-finite]: https://www.npmjs.com/package/@stdlib/math-base-assert-is-negative-finite
|
|
292
|
+
|
|
293
|
+
[@stdlib/math/base/assert/is-positive-finite]: https://www.npmjs.com/package/@stdlib/math-base-assert-is-positive-finite
|
|
294
|
+
|
|
295
|
+
[@stdlib/math/base/assert/is-nonpositive-finite]: https://www.npmjs.com/package/@stdlib/math-base-assert-is-nonpositive-finite
|
|
296
|
+
|
|
192
297
|
<!-- </related-links> -->
|
|
193
298
|
|
|
194
299
|
</section>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
#ifndef STDLIB_MATH_BASE_ASSERT_IS_NONNEGATIVE_FINITE_H
|
|
20
|
+
#define STDLIB_MATH_BASE_ASSERT_IS_NONNEGATIVE_FINITE_H
|
|
21
|
+
|
|
22
|
+
#include <stdbool.h>
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
|
|
26
|
+
*/
|
|
27
|
+
#ifdef __cplusplus
|
|
28
|
+
extern "C" {
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Tests if a numeric value is a nonnegative finite number.
|
|
33
|
+
*/
|
|
34
|
+
bool stdlib_base_is_nonnegative_finite( const double x );
|
|
35
|
+
|
|
36
|
+
#ifdef __cplusplus
|
|
37
|
+
}
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
#endif // !STDLIB_MATH_BASE_ASSERT_IS_NONNEGATIVE_FINITE_H
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var Boolean = require( '@stdlib/boolean-ctor' );
|
|
24
|
+
var addon = require( './../src/addon.node' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Tests if a numeric value is a nonnegative finite number.
|
|
31
|
+
*
|
|
32
|
+
* @private
|
|
33
|
+
* @param {number} x - value to test
|
|
34
|
+
* @returns {boolean} boolean indicating whether the number is nonnegative finite
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var bool = isNonNegativeFinite( 2.0 );
|
|
38
|
+
* // returns true
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* var bool = isNonNegativeFinite( -5.0 );
|
|
42
|
+
* // returns false
|
|
43
|
+
*/
|
|
44
|
+
function isNonNegativeFinite( x ) {
|
|
45
|
+
return Boolean( addon( x ) );
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
// EXPORTS //
|
|
50
|
+
|
|
51
|
+
module.exports = isNonNegativeFinite;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": {},
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"field": "src",
|
|
6
|
+
"resolve": true,
|
|
7
|
+
"relative": true
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"field": "include",
|
|
11
|
+
"resolve": true,
|
|
12
|
+
"relative": true
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"field": "libraries",
|
|
16
|
+
"resolve": false,
|
|
17
|
+
"relative": false
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"field": "libpath",
|
|
21
|
+
"resolve": true,
|
|
22
|
+
"relative": false
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"confs": [
|
|
26
|
+
{
|
|
27
|
+
"src": [
|
|
28
|
+
"./src/main.c"
|
|
29
|
+
],
|
|
30
|
+
"include": [
|
|
31
|
+
"./include"
|
|
32
|
+
],
|
|
33
|
+
"libraries": [],
|
|
34
|
+
"libpath": [],
|
|
35
|
+
"dependencies": [
|
|
36
|
+
"@stdlib/constants-float64-pinf"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/math-base-assert-is-nonnegative-finite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Test if a numeric value is a nonnegative finite number.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -14,9 +14,12 @@
|
|
|
14
14
|
}
|
|
15
15
|
],
|
|
16
16
|
"main": "./lib",
|
|
17
|
+
"gypfile": false,
|
|
17
18
|
"directories": {
|
|
18
19
|
"doc": "./docs",
|
|
20
|
+
"include": "./include",
|
|
19
21
|
"lib": "./lib",
|
|
22
|
+
"src": "./src",
|
|
20
23
|
"dist": "./dist"
|
|
21
24
|
},
|
|
22
25
|
"types": "./docs/types",
|
|
@@ -30,7 +33,8 @@
|
|
|
30
33
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
|
-
"@stdlib/constants-float64-pinf": "^0.2.
|
|
36
|
+
"@stdlib/constants-float64-pinf": "^0.2.2",
|
|
37
|
+
"@stdlib/utils-library-manifest": "^0.2.3"
|
|
34
38
|
},
|
|
35
39
|
"devDependencies": {},
|
|
36
40
|
"engines": {
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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/assert/is_nonnegative_finite.h"
|
|
20
|
+
#include <node_api.h>
|
|
21
|
+
#include <stdbool.h>
|
|
22
|
+
#include <stdint.h>
|
|
23
|
+
#include <assert.h>
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Receives JavaScript callback invocation data.
|
|
27
|
+
*
|
|
28
|
+
* @param env environment under which the function is invoked
|
|
29
|
+
* @param info callback data
|
|
30
|
+
* @return Node-API value
|
|
31
|
+
*/
|
|
32
|
+
static napi_value addon( napi_env env, napi_callback_info info ) {
|
|
33
|
+
napi_status status;
|
|
34
|
+
|
|
35
|
+
// Get callback arguments:
|
|
36
|
+
size_t argc = 1;
|
|
37
|
+
napi_value argv[ 1 ];
|
|
38
|
+
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
|
|
39
|
+
assert( status == napi_ok );
|
|
40
|
+
|
|
41
|
+
// Check whether we were provided the correct number of arguments:
|
|
42
|
+
if ( argc < 1 ) {
|
|
43
|
+
status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." );
|
|
44
|
+
assert( status == napi_ok );
|
|
45
|
+
return NULL;
|
|
46
|
+
}
|
|
47
|
+
if ( argc > 1 ) {
|
|
48
|
+
status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." );
|
|
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
|
+
double x;
|
|
63
|
+
status = napi_get_value_double( env, argv[ 0 ], &x );
|
|
64
|
+
assert( status == napi_ok );
|
|
65
|
+
|
|
66
|
+
bool result = stdlib_base_is_nonnegative_finite( x );
|
|
67
|
+
|
|
68
|
+
napi_value v;
|
|
69
|
+
status = napi_create_int32( env, (int32_t)result, &v );
|
|
70
|
+
assert( status == napi_ok );
|
|
71
|
+
|
|
72
|
+
return v;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Initializes a Node-API module.
|
|
77
|
+
*
|
|
78
|
+
* @param env environment under which the function is invoked
|
|
79
|
+
* @param exports exports object
|
|
80
|
+
* @return main export
|
|
81
|
+
*/
|
|
82
|
+
static napi_value init( napi_env env, napi_value exports ) {
|
|
83
|
+
napi_value fcn;
|
|
84
|
+
napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn );
|
|
85
|
+
assert( status == napi_ok );
|
|
86
|
+
return fcn;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
NAPI_MODULE( NODE_GYP_MODULE_NAME, init )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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/assert/is_nonnegative_finite.h"
|
|
20
|
+
#include "stdlib/constants/float64/pinf.h"
|
|
21
|
+
#include <stdbool.h>
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Tests if a numeric value is a nonnegative finite number.
|
|
25
|
+
*
|
|
26
|
+
* @param x input value
|
|
27
|
+
* @return output value
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* #include <stdbool.h>
|
|
31
|
+
*
|
|
32
|
+
* bool out = stdlib_base_is_nonnegative_finite( 3.0 );
|
|
33
|
+
* // returns true
|
|
34
|
+
*/
|
|
35
|
+
bool stdlib_base_is_nonnegative_finite( const double x ) {
|
|
36
|
+
return ( x >= 0.0 && x < STDLIB_CONSTANT_FLOAT64_PINF );
|
|
37
|
+
}
|