@stdlib/math-base-assert-is-probability 0.2.2 → 0.2.4

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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -79,18 +79,19 @@ bool = isProbability( NaN );
79
79
  <!-- eslint no-undef: "error" -->
80
80
 
81
81
  ```javascript
82
- var randu = require( '@stdlib/random-base-randu' );
82
+ var uniform = require( '@stdlib/random-array-uniform' );
83
+ var logEachMap = require( '@stdlib/console-log-each-map' );
83
84
  var isProbability = require( '@stdlib/math-base-assert-is-probability' );
84
85
 
85
- var bool;
86
- var x;
87
- var i;
86
+ var opts = {
87
+ 'dtype': 'float64'
88
+ };
89
+ var x = uniform( 100, -1.0, 1.0, opts );
88
90
 
89
- for ( i = 0; i < 100; i++ ) {
90
- x = ( randu()*2.0 ) - 1.0;
91
- bool = isProbability( x );
92
- console.log( '%d is %s', x, ( bool ) ? 'a probability' : 'not a probability' );
91
+ function isProbabilityWrapper( value ) {
92
+ return ( isProbability( value ) ) ? 'a probability' : 'not a probability';
93
93
  }
94
+ logEachMap( '%0.4f is %s', x, isProbabilityWrapper );
94
95
  ```
95
96
 
96
97
  </section>
@@ -128,6 +129,8 @@ for ( i = 0; i < 100; i++ ) {
128
129
  Tests if a double-precision floating-point number is a probability.
129
130
 
130
131
  ```c
132
+ #include <stdbool.h>
133
+
131
134
  bool out = stdlib_base_is_probability( 0.5 );
132
135
  // returns true
133
136
 
@@ -171,7 +174,7 @@ int main( void ) {
171
174
  double x;
172
175
  bool v;
173
176
  int i;
174
-
177
+
175
178
  for ( i = 0; i < 100; i++ ) {
176
179
  x = ( ( (double)rand() / (double)RAND_MAX ) * 2.0 ) - 1.0;
177
180
  v = stdlib_base_is_probability( x );
@@ -222,7 +225,7 @@ See [LICENSE][stdlib-license].
222
225
 
223
226
  ## Copyright
224
227
 
225
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
228
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
226
229
 
227
230
  </section>
228
231
 
@@ -235,8 +238,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
235
238
  [npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-assert-is-probability.svg
236
239
  [npm-url]: https://npmjs.org/package/@stdlib/math-base-assert-is-probability
237
240
 
238
- [test-image]: https://github.com/stdlib-js/math-base-assert-is-probability/actions/workflows/test.yml/badge.svg?branch=v0.2.2
239
- [test-url]: https://github.com/stdlib-js/math-base-assert-is-probability/actions/workflows/test.yml?query=branch:v0.2.2
241
+ [test-image]: https://github.com/stdlib-js/math-base-assert-is-probability/actions/workflows/test.yml/badge.svg?branch=v0.2.4
242
+ [test-url]: https://github.com/stdlib-js/math-base-assert-is-probability/actions/workflows/test.yml?query=branch:v0.2.4
240
243
 
241
244
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-assert-is-probability/main.svg
242
245
  [coverage-url]: https://codecov.io/github/stdlib-js/math-base-assert-is-probability?branch=main
@@ -248,8 +251,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
248
251
 
249
252
  -->
250
253
 
251
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
252
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
254
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
255
+ [chat-url]: https://stdlib.zulipchat.com
253
256
 
254
257
  [stdlib]: https://github.com/stdlib-js/stdlib
255
258
 
package/manifest.json CHANGED
@@ -1,5 +1,7 @@
1
1
  {
2
- "options": {},
2
+ "options": {
3
+ "task": "build"
4
+ },
3
5
  "fields": [
4
6
  {
5
7
  "field": "src",
@@ -24,6 +26,36 @@
24
26
  ],
25
27
  "confs": [
26
28
  {
29
+ "task": "build",
30
+ "src": [
31
+ "./src/main.c"
32
+ ],
33
+ "include": [
34
+ "./include"
35
+ ],
36
+ "libraries": [],
37
+ "libpath": [],
38
+ "dependencies": [
39
+ "@stdlib/napi-argv",
40
+ "@stdlib/napi-argv-double",
41
+ "@stdlib/napi-create-int32",
42
+ "@stdlib/napi-export"
43
+ ]
44
+ },
45
+ {
46
+ "task": "benchmark",
47
+ "src": [
48
+ "./src/main.c"
49
+ ],
50
+ "include": [
51
+ "./include"
52
+ ],
53
+ "libraries": [],
54
+ "libpath": [],
55
+ "dependencies": []
56
+ },
57
+ {
58
+ "task": "examples",
27
59
  "src": [
28
60
  "./src/main.c"
29
61
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/math-base-assert-is-probability",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Test if a double-precision floating-point number is a probability.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -33,7 +33,11 @@
33
33
  "url": "https://github.com/stdlib-js/stdlib/issues"
34
34
  },
35
35
  "dependencies": {
36
- "@stdlib/utils-library-manifest": "^0.2.1"
36
+ "@stdlib/napi-argv": "^0.2.2",
37
+ "@stdlib/napi-argv-double": "^0.2.1",
38
+ "@stdlib/napi-create-int32": "^0.0.3",
39
+ "@stdlib/napi-export": "^0.3.0",
40
+ "@stdlib/utils-library-manifest": "^0.2.3"
37
41
  },
38
42
  "devDependencies": {},
39
43
  "engines": {
package/src/addon.c CHANGED
@@ -17,74 +17,25 @@
17
17
  */
18
18
 
19
19
  #include "stdlib/math/base/assert/is_probability.h"
20
+ #include "stdlib/napi/argv.h"
21
+ #include "stdlib/napi/argv_double.h"
22
+ #include "stdlib/napi/create_int32.h"
23
+ #include "stdlib/napi/export.h"
20
24
  #include <node_api.h>
21
25
  #include <stdint.h>
22
- #include <assert.h>
23
26
 
24
27
  /**
25
28
  * Receives JavaScript callback invocation data.
26
29
  *
27
- * @private
28
30
  * @param env environment under which the function is invoked
29
31
  * @param info callback data
30
32
  * @return Node-API value
31
33
  */
32
34
  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_probability( 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
- * @private
79
- * @param env environment under which the function is invoked
80
- * @param exports exports object
81
- * @return main export
82
- */
83
- static napi_value init( napi_env env, napi_value exports ) {
84
- napi_value fcn;
85
- napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn );
86
- assert( status == napi_ok );
87
- return fcn;
35
+ STDLIB_NAPI_ARGV( env, info, argv, argc, 1 );
36
+ STDLIB_NAPI_ARGV_DOUBLE( env, x, argv, 0 );
37
+ STDLIB_NAPI_CREATE_INT32( env, (int32_t)stdlib_base_is_probability( x ), out );
38
+ return out;
88
39
  }
89
40
 
90
- NAPI_MODULE( NODE_GYP_MODULE_NAME, init )
41
+ STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
package/src/main.c CHANGED
@@ -23,7 +23,7 @@
23
23
  * Tests if a double-precision floating-point number is a probability.
24
24
  *
25
25
  * @param x input value
26
- * @return output value
26
+ * @return output value
27
27
  *
28
28
  * @example
29
29
  * #include <stdbool.h>
@@ -35,5 +35,5 @@
35
35
  * // returns false
36
36
  */
37
37
  bool stdlib_base_is_probability( const double x ) {
38
- return ( x >= 0.0 && x <= 1.0 );
38
+ return ( x >= 0.0 && x <= 1.0 );
39
39
  }