@stdlib/math-base-assert-is-probabilityf 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
package/NOTICE ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md ADDED
@@ -0,0 +1,276 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2025 The Stdlib Authors.
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ -->
20
+
21
+
22
+ <details>
23
+ <summary>
24
+ About stdlib...
25
+ </summary>
26
+ <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
27
+ <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
28
+ <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
29
+ <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30
+ </details>
31
+
32
+ # isProbabilityf
33
+
34
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
35
+
36
+ > Test if a single-precision floating-point number is a probability.
37
+
38
+ <section class="installation">
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ npm install @stdlib/math-base-assert-is-probabilityf
44
+ ```
45
+
46
+ </section>
47
+
48
+ <section class="usage">
49
+
50
+ ## Usage
51
+
52
+ ```javascript
53
+ var isProbabilityf = require( '@stdlib/math-base-assert-is-probabilityf' );
54
+ ```
55
+
56
+ #### isProbabilityf( x )
57
+
58
+ Tests if a single-precision floating-point number is a probability.
59
+
60
+ ```javascript
61
+ var bool = isProbabilityf( 0.5 );
62
+ // returns true
63
+
64
+ bool = isProbabilityf( 3.14 );
65
+ // returns false
66
+
67
+ bool = isProbabilityf( NaN );
68
+ // returns false
69
+ ```
70
+
71
+ </section>
72
+
73
+ <!-- /.usage -->
74
+
75
+ <section class="examples">
76
+
77
+ ## Examples
78
+
79
+ <!-- eslint no-undef: "error" -->
80
+
81
+ ```javascript
82
+ var uniform = require( '@stdlib/random-array-uniform' );
83
+ var logEachMap = require( '@stdlib/console-log-each-map' );
84
+ var isProbabilityf = require( '@stdlib/math-base-assert-is-probabilityf' );
85
+
86
+ var opts = {
87
+ 'dtype': 'float32'
88
+ };
89
+ var x = uniform( 100, -1.0, 1.0, opts );
90
+
91
+ function isProbabilityfWrapper( value ) {
92
+ return ( isProbabilityf( value ) ) ? 'a probability' : 'not a probability';
93
+ }
94
+ logEachMap( '%0.4f is %s', x, isProbabilityfWrapper );
95
+ ```
96
+
97
+ </section>
98
+
99
+ <!-- /.examples -->
100
+
101
+ <!-- C interface documentation. -->
102
+
103
+ * * *
104
+
105
+ <section class="c">
106
+
107
+ ## C APIs
108
+
109
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
110
+
111
+ <section class="intro">
112
+
113
+ </section>
114
+
115
+ <!-- /.intro -->
116
+
117
+ <!-- C usage documentation. -->
118
+
119
+ <section class="usage">
120
+
121
+ ### Usage
122
+
123
+ ```c
124
+ #include "stdlib/math/base/assert/is_probabilityf.h"
125
+ ```
126
+
127
+ #### stdlib_base_is_probabilityf( x )
128
+
129
+ Tests if a single-precision floating-point number is a probability.
130
+
131
+ ```c
132
+ #include <stdbool.h>
133
+
134
+ bool out = stdlib_base_is_probabilityf( 0.5f );
135
+ // returns true
136
+
137
+ out = stdlib_base_is_probabilityf( 3.14f );
138
+ // returns false
139
+ ```
140
+
141
+ The function accepts the following arguments:
142
+
143
+ - **x**: `[in] float` input value.
144
+
145
+ ```c
146
+ bool stdlib_base_is_probabilityf( const float x );
147
+ ```
148
+
149
+ </section>
150
+
151
+ <!-- /.usage -->
152
+
153
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
154
+
155
+ <section class="notes">
156
+
157
+ </section>
158
+
159
+ <!-- /.notes -->
160
+
161
+ <!-- C API usage examples. -->
162
+
163
+ <section class="examples">
164
+
165
+ ### Examples
166
+
167
+ ```c
168
+ #include "stdlib/math/base/assert/is_probabilityf.h"
169
+ #include <stdio.h>
170
+ #include <stdlib.h>
171
+ #include <stdbool.h>
172
+
173
+ int main( void ) {
174
+ float x;
175
+ bool v;
176
+ int i;
177
+
178
+ for ( i = 0; i < 100; i++ ) {
179
+ x = ( ( (float)rand() / (float)RAND_MAX ) * 2.0f ) - 1.0f;
180
+ v = stdlib_base_is_probabilityf( x );
181
+ printf( "%f is %sa probability\n", x, ( v ) ? "" : "not " );
182
+ }
183
+ }
184
+ ```
185
+
186
+ </section>
187
+
188
+ <!-- /.examples -->
189
+
190
+ </section>
191
+
192
+ <!-- /.c -->
193
+
194
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
195
+
196
+ <section class="related">
197
+
198
+ </section>
199
+
200
+ <!-- /.related -->
201
+
202
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
203
+
204
+
205
+ <section class="main-repo" >
206
+
207
+ * * *
208
+
209
+ ## Notice
210
+
211
+ This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
212
+
213
+ For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
214
+
215
+ #### Community
216
+
217
+ [![Chat][chat-image]][chat-url]
218
+
219
+ ---
220
+
221
+ ## License
222
+
223
+ See [LICENSE][stdlib-license].
224
+
225
+
226
+ ## Copyright
227
+
228
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
229
+
230
+ </section>
231
+
232
+ <!-- /.stdlib -->
233
+
234
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
235
+
236
+ <section class="links">
237
+
238
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-assert-is-probabilityf.svg
239
+ [npm-url]: https://npmjs.org/package/@stdlib/math-base-assert-is-probabilityf
240
+
241
+ [test-image]: https://github.com/stdlib-js/math-base-assert-is-probabilityf/actions/workflows/test.yml/badge.svg?branch=v0.1.0
242
+ [test-url]: https://github.com/stdlib-js/math-base-assert-is-probabilityf/actions/workflows/test.yml?query=branch:v0.1.0
243
+
244
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-assert-is-probabilityf/main.svg
245
+ [coverage-url]: https://codecov.io/github/stdlib-js/math-base-assert-is-probabilityf?branch=main
246
+
247
+ <!--
248
+
249
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/math-base-assert-is-probabilityf.svg
250
+ [dependencies-url]: https://david-dm.org/stdlib-js/math-base-assert-is-probabilityf/main
251
+
252
+ -->
253
+
254
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
255
+ [chat-url]: https://stdlib.zulipchat.com
256
+
257
+ [stdlib]: https://github.com/stdlib-js/stdlib
258
+
259
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
260
+
261
+ [umd]: https://github.com/umdjs/umd
262
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
263
+
264
+ [deno-url]: https://github.com/stdlib-js/math-base-assert-is-probabilityf/tree/deno
265
+ [deno-readme]: https://github.com/stdlib-js/math-base-assert-is-probabilityf/blob/deno/README.md
266
+ [umd-url]: https://github.com/stdlib-js/math-base-assert-is-probabilityf/tree/umd
267
+ [umd-readme]: https://github.com/stdlib-js/math-base-assert-is-probabilityf/blob/umd/README.md
268
+ [esm-url]: https://github.com/stdlib-js/math-base-assert-is-probabilityf/tree/esm
269
+ [esm-readme]: https://github.com/stdlib-js/math-base-assert-is-probabilityf/blob/esm/README.md
270
+ [branches-url]: https://github.com/stdlib-js/math-base-assert-is-probabilityf/blob/main/branches.md
271
+
272
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/math-base-assert-is-probabilityf/main/LICENSE
273
+
274
+ </section>
275
+
276
+ <!-- /.links -->
package/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security
2
+
3
+ > Policy for reporting security vulnerabilities.
4
+
5
+ See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security).
@@ -0,0 +1,3 @@
1
+ /// <reference path="../docs/types/index.d.ts" />
2
+ import isProbabilityf from '../docs/types/index';
3
+ export = isProbabilityf;
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";var s=function(r,t){return function(){return t||r((t={exports:{}}).exports,t),t.exports}};var e=s(function(a,i){
2
+ function u(r){return r>=0&&r<=1}i.exports=u
3
+ });var n=e();module.exports=n;
4
+ /** @license Apache-2.0 */
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a single-precision floating-point number is a probability.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is a probability\n*\n* @example\n* var bool = isProbabilityf( 0.5 );\n* // returns true\n*\n* @example\n* var bool = isProbabilityf( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isProbabilityf( NaN );\n* // returns false\n*/\nfunction isProbabilityf( x ) {\n\treturn ( x >= 0.0 && x <= 1.0 );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isProbabilityf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Test if a single-precision floating-point number is a probability.\n*\n* @module @stdlib/math-base-assert-is-probabilityf\n*\n* @example\n* var isProbabilityf = require( '@stdlib/math-base-assert-is-probabilityf' );\n*\n* var bool = isProbabilityf( 0.5 );\n* // returns true\n*\n* bool = isProbabilityf( 3.14 );\n* // returns false\n*\n* bool = isProbabilityf( NaN );\n* // returns false\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsCA,SAASC,EAAgBC,EAAI,CAC5B,OAASA,GAAK,GAAOA,GAAK,CAC3B,CAKAF,EAAO,QAAUC,ICLjB,IAAIE,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_main", "__commonJSMin", "exports", "module", "isProbabilityf", "x", "main"]
7
+ }
@@ -0,0 +1,48 @@
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
+ // TypeScript Version: 4.1
20
+
21
+ /**
22
+ * Tests if a single-precision floating-point number is a probability.
23
+ *
24
+ * ## Notes
25
+ *
26
+ * - A probability is defined as a number on the closed interval `[0,1]`.
27
+ *
28
+ * @param x - value to test
29
+ * @returns boolean indicating whether the value is a probability
30
+ *
31
+ * @example
32
+ * var bool = isProbabilityf( 0.5 );
33
+ * // returns true
34
+ *
35
+ * @example
36
+ * var bool = isProbabilityf( 3.14 );
37
+ * // returns false
38
+ *
39
+ * @example
40
+ * var bool = isProbabilityf( NaN );
41
+ * // returns false
42
+ */
43
+ declare function isProbabilityf( x: number ): boolean;
44
+
45
+
46
+ // EXPORTS //
47
+
48
+ export = isProbabilityf;
@@ -0,0 +1,40 @@
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
+ #ifndef STDLIB_MATH_BASE_ASSERT_IS_PROBABILITYF_H
20
+ #define STDLIB_MATH_BASE_ASSERT_IS_PROBABILITYF_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 single-precision floating-point number is a probability.
33
+ */
34
+ bool stdlib_base_is_probabilityf( const float x );
35
+
36
+ #ifdef __cplusplus
37
+ }
38
+ #endif
39
+
40
+ #endif // !STDLIB_MATH_BASE_ASSERT_IS_PROBABILITYF_H
package/lib/index.js ADDED
@@ -0,0 +1,46 @@
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
+ 'use strict';
20
+
21
+ /**
22
+ * Test if a single-precision floating-point number is a probability.
23
+ *
24
+ * @module @stdlib/math-base-assert-is-probabilityf
25
+ *
26
+ * @example
27
+ * var isProbabilityf = require( '@stdlib/math-base-assert-is-probabilityf' );
28
+ *
29
+ * var bool = isProbabilityf( 0.5 );
30
+ * // returns true
31
+ *
32
+ * bool = isProbabilityf( 3.14 );
33
+ * // returns false
34
+ *
35
+ * bool = isProbabilityf( NaN );
36
+ * // returns false
37
+ */
38
+
39
+ // MODULES //
40
+
41
+ var main = require( './main.js' );
42
+
43
+
44
+ // EXPORTS //
45
+
46
+ module.exports = main;
package/lib/main.js ADDED
@@ -0,0 +1,46 @@
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
+ 'use strict';
20
+
21
+ /**
22
+ * Tests if a single-precision floating-point number is a probability.
23
+ *
24
+ * @param {number} x - value to test
25
+ * @returns {boolean} boolean indicating whether the value is a probability
26
+ *
27
+ * @example
28
+ * var bool = isProbabilityf( 0.5 );
29
+ * // returns true
30
+ *
31
+ * @example
32
+ * var bool = isProbabilityf( 3.14 );
33
+ * // returns false
34
+ *
35
+ * @example
36
+ * var bool = isProbabilityf( NaN );
37
+ * // returns false
38
+ */
39
+ function isProbabilityf( x ) {
40
+ return ( x >= 0.0 && x <= 1.0 );
41
+ }
42
+
43
+
44
+ // EXPORTS //
45
+
46
+ module.exports = isProbabilityf;
package/lib/native.js ADDED
@@ -0,0 +1,55 @@
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
+ '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 single-precision floating-point number is a probability.
31
+ *
32
+ * @private
33
+ * @param {number} x - value to test
34
+ * @returns {boolean} boolean indicating whether the value is a probability
35
+ *
36
+ * @example
37
+ * var bool = isProbabilityf( 0.5 );
38
+ * // returns true
39
+ *
40
+ * @example
41
+ * var bool = isProbabilityf( 3.14 );
42
+ * // returns false
43
+ *
44
+ * @example
45
+ * var bool = isProbabilityf( NaN );
46
+ * // returns false
47
+ */
48
+ function isProbabilityf( x ) {
49
+ return Boolean( addon( x ) );
50
+ }
51
+
52
+
53
+ // EXPORTS //
54
+
55
+ module.exports = isProbabilityf;
package/manifest.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "options": {
3
+ "task": "build"
4
+ },
5
+ "fields": [
6
+ {
7
+ "field": "src",
8
+ "resolve": true,
9
+ "relative": true
10
+ },
11
+ {
12
+ "field": "include",
13
+ "resolve": true,
14
+ "relative": true
15
+ },
16
+ {
17
+ "field": "libraries",
18
+ "resolve": false,
19
+ "relative": false
20
+ },
21
+ {
22
+ "field": "libpath",
23
+ "resolve": true,
24
+ "relative": false
25
+ }
26
+ ],
27
+ "confs": [
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-float",
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",
59
+ "src": [
60
+ "./src/main.c"
61
+ ],
62
+ "include": [
63
+ "./include"
64
+ ],
65
+ "libraries": [],
66
+ "libpath": [],
67
+ "dependencies": []
68
+ }
69
+ ]
70
+ }
package/package.json ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "@stdlib/math-base-assert-is-probabilityf",
3
+ "version": "0.1.0",
4
+ "description": "Test if a single-precision floating-point number is a probability.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "gypfile": false,
18
+ "directories": {
19
+ "doc": "./docs",
20
+ "include": "./include",
21
+ "lib": "./lib",
22
+ "src": "./src",
23
+ "dist": "./dist"
24
+ },
25
+ "types": "./docs/types",
26
+ "scripts": {},
27
+ "homepage": "https://stdlib.io",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git://github.com/stdlib-js/math-base-assert-is-probabilityf.git"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/stdlib-js/stdlib/issues"
34
+ },
35
+ "dependencies": {
36
+ "@stdlib/napi-argv": "^0.2.2",
37
+ "@stdlib/napi-argv-float": "^0.2.2",
38
+ "@stdlib/napi-create-int32": "^0.0.2",
39
+ "@stdlib/napi-export": "^0.3.0",
40
+ "@stdlib/utils-library-manifest": "^0.2.3"
41
+ },
42
+ "devDependencies": {},
43
+ "engines": {
44
+ "node": ">=0.10.0",
45
+ "npm": ">2.7.0"
46
+ },
47
+ "os": [
48
+ "aix",
49
+ "darwin",
50
+ "freebsd",
51
+ "linux",
52
+ "macos",
53
+ "openbsd",
54
+ "sunos",
55
+ "win32",
56
+ "windows"
57
+ ],
58
+ "keywords": [
59
+ "stdlib",
60
+ "stdmath",
61
+ "assertion",
62
+ "assert",
63
+ "utilities",
64
+ "utility",
65
+ "utils",
66
+ "util",
67
+ "math",
68
+ "mathematics",
69
+ "float",
70
+ "number",
71
+ "numeric",
72
+ "probability",
73
+ "prob",
74
+ "is",
75
+ "isprobabilityf",
76
+ "isprob",
77
+ "type",
78
+ "check",
79
+ "valid",
80
+ "validate",
81
+ "test"
82
+ ],
83
+ "funding": {
84
+ "type": "opencollective",
85
+ "url": "https://opencollective.com/stdlib"
86
+ }
87
+ }
package/src/addon.c ADDED
@@ -0,0 +1,41 @@
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/assert/is_probabilityf.h"
20
+ #include "stdlib/napi/argv.h"
21
+ #include "stdlib/napi/argv_float.h"
22
+ #include "stdlib/napi/create_int32.h"
23
+ #include "stdlib/napi/export.h"
24
+ #include <node_api.h>
25
+ #include <stdint.h>
26
+
27
+ /**
28
+ * Receives JavaScript callback invocation data.
29
+ *
30
+ * @param env environment under which the function is invoked
31
+ * @param info callback data
32
+ * @return Node-API value
33
+ */
34
+ static napi_value addon( napi_env env, napi_callback_info info ) {
35
+ STDLIB_NAPI_ARGV( env, info, argv, argc, 1 );
36
+ STDLIB_NAPI_ARGV_FLOAT( env, x, argv, 0 );
37
+ STDLIB_NAPI_CREATE_INT32( env, (int32_t)stdlib_base_is_probabilityf( x ), out );
38
+ return out;
39
+ }
40
+
41
+ STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
package/src/main.c ADDED
@@ -0,0 +1,39 @@
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/assert/is_probabilityf.h"
20
+ #include <stdbool.h>
21
+
22
+ /**
23
+ * Tests if a single-precision floating-point number is a probability.
24
+ *
25
+ * @param x input value
26
+ * @return output value
27
+ *
28
+ * @example
29
+ * #include <stdbool.h>
30
+ *
31
+ * bool out = stdlib_base_is_probabilityf( 0.5f );
32
+ * // returns true
33
+ *
34
+ * out = stdlib_base_is_probabilityf( 1.5f );
35
+ * // returns false
36
+ */
37
+ bool stdlib_base_is_probabilityf( const float x ) {
38
+ return ( x >= 0.0f && x <= 1.0f );
39
+ }