@stdlib/math-base-assert-is-nonpositive-integer 0.2.0 → 0.2.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/README.md CHANGED
@@ -133,6 +133,97 @@ bool = isNonPositiveInteger( NaN );
133
133
 
134
134
  <!-- /.examples -->
135
135
 
136
+ <!-- C interface documentation. -->
137
+
138
+ * * *
139
+
140
+ <section class="c">
141
+
142
+ ## C APIs
143
+
144
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
145
+
146
+ <section class="intro">
147
+
148
+ </section>
149
+
150
+ <!-- /.intro -->
151
+
152
+ <!-- C usage documentation. -->
153
+
154
+ <section class="usage">
155
+
156
+ ### Usage
157
+
158
+ ```c
159
+ #include "stdlib/math/base/assert/is_nonpositive_integer.h"
160
+ ```
161
+
162
+ #### stdlib_base_is_nonpositive_integer( x )
163
+
164
+ Tests if a finite double-precision floating-point number is a nonpositive integer.
165
+
166
+ ```c
167
+ #include <stdbool.h>
168
+
169
+ bool out = stdlib_base_is_nonpositive_integer( -5.0 );
170
+ // returns true
171
+
172
+ out = stdlib_base_is_nonpositive_integer( 0.0 );
173
+ // returns true
174
+ ```
175
+
176
+ The function accepts the following arguments:
177
+
178
+ - **x**: `[in] double` input value.
179
+
180
+ ```c
181
+ bool stdlib_base_is_nonpositive_integer( const double x );
182
+ ```
183
+
184
+ </section>
185
+
186
+ <!-- /.usage -->
187
+
188
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
189
+
190
+ <section class="notes">
191
+
192
+ </section>
193
+
194
+ <!-- /.notes -->
195
+
196
+ <!-- C API usage examples. -->
197
+
198
+ <section class="examples">
199
+
200
+ ### Examples
201
+
202
+ ```c
203
+ #include "stdlib/math/base/assert/is_nonpositive_integer.h"
204
+ #include <stdio.h>
205
+ #include <stdbool.h>
206
+
207
+ int main( void ) {
208
+ const double x[] = { 5.0, -5.0, 3.14, -3.14, 0.0, 0.0/0.0 };
209
+
210
+ bool b;
211
+ int i;
212
+ for ( i = 0; i < 6; i++ ) {
213
+ b = stdlib_base_is_nonpositive_integer( x[ i ] );
214
+ printf( "x = %lf, is_nonpositive_integer(x) = %s\n", x[ i ], ( b ) ? "True" : "False" );
215
+ }
216
+ }
217
+ ```
218
+
219
+ </section>
220
+
221
+ <!-- /.examples -->
222
+
223
+ </section>
224
+
225
+ <!-- /.c -->
226
+
136
227
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
137
228
 
138
229
  <section class="related">
@@ -189,11 +280,11 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
189
280
  [npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-assert-is-nonpositive-integer.svg
190
281
  [npm-url]: https://npmjs.org/package/@stdlib/math-base-assert-is-nonpositive-integer
191
282
 
192
- [test-image]: https://github.com/stdlib-js/math-base-assert-is-nonpositive-integer/actions/workflows/test.yml/badge.svg?branch=v0.2.0
193
- [test-url]: https://github.com/stdlib-js/math-base-assert-is-nonpositive-integer/actions/workflows/test.yml?query=branch:v0.2.0
283
+ [test-image]: https://github.com/stdlib-js/math-base-assert-is-nonpositive-integer/actions/workflows/test.yml/badge.svg?branch=v0.2.1
284
+ [test-url]: https://github.com/stdlib-js/math-base-assert-is-nonpositive-integer/actions/workflows/test.yml?query=branch:v0.2.1
194
285
 
195
286
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-assert-is-nonpositive-integer/main.svg
196
- [coverage-url]: https://codecov.io/github/stdlib-js/math-base-assert-is-nonpositive-integer?branch=main
287
+ [coverage-url]: https://codecov.io/github/stdlib-js/math-base-assert-is-nonpositive-integer?branch=v0.2.1
197
288
 
198
289
  <!--
199
290
 
@@ -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_NONPOSITIVE_INTEGER_H
20
+ #define STDLIB_MATH_BASE_ASSERT_IS_NONPOSITIVE_INTEGER_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 finite double-precision floating-point number is a nonpositive integer.
33
+ */
34
+ bool stdlib_base_is_nonpositive_integer( const double x );
35
+
36
+ #ifdef __cplusplus
37
+ }
38
+ #endif
39
+
40
+ #endif // !STDLIB_MATH_BASE_ASSERT_IS_NONPOSITIVE_INTEGER_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 finite double-precision floating-point number is a nonpositive integer.
31
+ *
32
+ * @private
33
+ * @param {number} x - value to test
34
+ * @returns {boolean} boolean indicating whether the number is nonpositive integer
35
+ *
36
+ * @example
37
+ * var bool = isNonPositiveInteger( -2.0 );
38
+ * // returns true
39
+ *
40
+ * @example
41
+ * var bool = isNonPositiveInteger( 5.0 );
42
+ * // returns false
43
+ */
44
+ function isNonPositiveInteger( x ) {
45
+ return Boolean( addon( x ) );
46
+ }
47
+
48
+
49
+ // EXPORTS //
50
+
51
+ module.exports = isNonPositiveInteger;
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/math-base-special-floor"
37
+ ]
38
+ }
39
+ ]
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/math-base-assert-is-nonpositive-integer",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Test if a finite double-precision floating-point number is a nonpositive integer.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -14,11 +14,14 @@
14
14
  }
15
15
  ],
16
16
  "main": "./lib",
17
+ "gypfile": false,
17
18
  "directories": {
18
19
  "benchmark": "./benchmark",
19
20
  "doc": "./docs",
20
21
  "example": "./examples",
22
+ "include": "./include",
21
23
  "lib": "./lib",
24
+ "src": "./src",
22
25
  "test": "./test"
23
26
  },
24
27
  "types": "./docs/types",
@@ -37,20 +40,22 @@
37
40
  "url": "https://github.com/stdlib-js/stdlib/issues"
38
41
  },
39
42
  "dependencies": {
40
- "@stdlib/math-base-special-floor": "^0.2.0"
43
+ "@stdlib/math-base-special-floor": "^0.2.3",
44
+ "@stdlib/utils-library-manifest": "^0.2.2"
41
45
  },
42
46
  "devDependencies": {
43
- "@stdlib/assert-is-boolean": "^0.1.1",
44
- "@stdlib/constants-float64-ninf": "^0.1.1",
45
- "@stdlib/constants-float64-pinf": "^0.1.1",
46
- "@stdlib/math-base-special-round": "^0.1.1",
47
- "@stdlib/math-base-special-trunc": "^0.1.1",
48
- "@stdlib/random-base-randu": "^0.1.0",
47
+ "@stdlib/assert-is-boolean": "^0.2.2",
48
+ "@stdlib/boolean-ctor": "^0.2.2",
49
+ "@stdlib/constants-float64-ninf": "^0.2.2",
50
+ "@stdlib/constants-float64-pinf": "^0.2.2",
51
+ "@stdlib/math-base-special-round": "^0.3.0",
52
+ "@stdlib/math-base-special-trunc": "^0.2.1",
53
+ "@stdlib/random-base-randu": "^0.2.1",
54
+ "@stdlib/utils-try-require": "^0.2.2",
49
55
  "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
50
56
  "istanbul": "^0.4.1",
51
57
  "tap-min": "git+https://github.com/Planeshifter/tap-min.git",
52
- "@stdlib/bench-harness": "^0.1.2",
53
- "@stdlib/bench": "^0.3.1"
58
+ "@stdlib/bench-harness": "^0.2.1"
54
59
  },
55
60
  "engines": {
56
61
  "node": ">=0.10.0",
package/src/addon.c ADDED
@@ -0,0 +1,88 @@
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_nonpositive_integer.h"
20
+ #include <node_api.h>
21
+ #include <stdint.h>
22
+ #include <assert.h>
23
+
24
+ /**
25
+ * Receives JavaScript callback invocation data.
26
+ *
27
+ * @param env environment under which the function is invoked
28
+ * @param info callback data
29
+ * @return Node-API value
30
+ */
31
+ static napi_value addon( napi_env env, napi_callback_info info ) {
32
+ napi_status status;
33
+
34
+ // Get callback arguments:
35
+ size_t argc = 1;
36
+ napi_value argv[ 1 ];
37
+ status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
38
+ assert( status == napi_ok );
39
+
40
+ // Check whether we were provided the correct number of arguments:
41
+ if ( argc < 1 ) {
42
+ status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." );
43
+ assert( status == napi_ok );
44
+ return NULL;
45
+ }
46
+ if ( argc > 1 ) {
47
+ status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." );
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
+ double x;
62
+ status = napi_get_value_double( env, argv[ 0 ], &x );
63
+ assert( status == napi_ok );
64
+
65
+ bool result = stdlib_base_is_nonpositive_integer( x );
66
+
67
+ napi_value v;
68
+ status = napi_create_int32( env, (int32_t)result, &v );
69
+ assert( status == napi_ok );
70
+
71
+ return v;
72
+ }
73
+
74
+ /**
75
+ * Initializes a Node-API module.
76
+ *
77
+ * @param env environment under which the function is invoked
78
+ * @param exports exports object
79
+ * @return main export
80
+ */
81
+ static napi_value init( napi_env env, napi_value exports ) {
82
+ napi_value fcn;
83
+ napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn );
84
+ assert( status == napi_ok );
85
+ return fcn;
86
+ }
87
+
88
+ NAPI_MODULE( NODE_GYP_MODULE_NAME, init )
package/src/main.c ADDED
@@ -0,0 +1,36 @@
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_nonpositive_integer.h"
20
+ #include "stdlib/math/base/special/floor.h"
21
+
22
+ /**
23
+ * Tests if a finite double-precision floating-point number is a nonpositive integer.
24
+ *
25
+ * @param x input value
26
+ * @return output value
27
+ *
28
+ * @example
29
+ * #include <stdbool.h>
30
+ *
31
+ * bool out = stdlib_base_is_nonpositive_integer( 3.0 );
32
+ * // returns false
33
+ */
34
+ bool stdlib_base_is_nonpositive_integer( const double x ) {
35
+ return ( stdlib_base_floor( x ) == x && x <= 0 );
36
+ }