-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add number/float16/base/assert/is-positive-zero
#9643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Planeshifter
merged 4 commits into
stdlib-js:develop
from
Neerajpathak07:float16/base/is-positive-zero
Jan 10, 2026
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
lib/node_modules/@stdlib/number/float16/base/assert/is-positive-zero/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| <!-- | ||
|
|
||
| @license Apache-2.0 | ||
|
|
||
| Copyright (c) 2026 The Stdlib Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
|
|
||
| --> | ||
|
|
||
| # isPositiveZero | ||
|
|
||
| > Test if a half-precision floating-point numeric value is positive zero. | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| var isPositiveZero = require( '@stdlib/number/float16/base/assert/is-positive-zero' ); | ||
| ``` | ||
|
|
||
| #### isPositiveZero( x ) | ||
|
|
||
| Tests if a half-precision floating-point `numeric` value is positive zero. | ||
|
|
||
| ```javascript | ||
| var bool = isPositiveZero( 0.0 ); | ||
| // returns true | ||
|
|
||
| bool = isPositiveZero( -0.0 ); | ||
| // returns false | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ## Examples | ||
|
|
||
| <!-- eslint no-undef: "error" --> | ||
|
|
||
| ```javascript | ||
| var isPositiveZero = require( '@stdlib/number/float16/base/assert/is-positive-zero' ); | ||
|
|
||
| var bool = isPositiveZero( 0.0 ); | ||
| // returns true | ||
|
|
||
| bool = isPositiveZero( -0.0 ); | ||
| // returns false | ||
|
|
||
| bool = isPositiveZero( 5.0 ); | ||
| // returns false | ||
|
|
||
| bool = isPositiveZero( -1.0 ); | ||
| // returns false | ||
|
|
||
| bool = isPositiveZero( NaN ); | ||
| // returns false | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.examples --> | ||
|
|
||
| <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
|
||
| <section class="related"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.related --> | ||
|
|
||
| <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="links"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.links --> |
55 changes: 55 additions & 0 deletions
55
lib/node_modules/@stdlib/number/float16/base/assert/is-positive-zero/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| // MODULES // | ||
|
|
||
| var bench = require( '@stdlib/bench' ); | ||
| var uniform = require( '@stdlib/random/array/uniform' ); | ||
| var toFloat16 = require( '@stdlib/number/float64/base/to-float16' ); | ||
| var map = require( '@stdlib/array/base/map' ); | ||
| var naryFunction = require( '@stdlib/utils/nary-function' ); | ||
| var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; | ||
| var pkg = require( './../package.json' ).name; | ||
| var isPositiveZero = require( './../lib' ); | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| bench( pkg, function benchmark( b ) { | ||
| var x; | ||
| var y; | ||
| var i; | ||
|
|
||
| x = map( uniform( 100, -5.0e4, 5.0e4 ), naryFunction( toFloat16, 1 ) ); | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| y = isPositiveZero( x[ i%x.length ] ); | ||
| if ( typeof y !== 'boolean' ) { | ||
| b.fail( 'should return a boolean' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( !isBoolean( y ) ) { | ||
| b.fail( 'should return a boolean' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| }); |
24 changes: 24 additions & 0 deletions
24
lib/node_modules/@stdlib/number/float16/base/assert/is-positive-zero/docs/repl.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
|
|
||
| {{alias}}( x ) | ||
| Tests if a half-precision floating-point numeric value is positive zero. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| x: number | ||
| Value to test. | ||
|
|
||
| Returns | ||
| ------- | ||
| bool: boolean | ||
| Boolean indicating whether the value is positive zero. | ||
|
|
||
| Examples | ||
| -------- | ||
| > var bool = {{alias}}( 0.0 ) | ||
| true | ||
| > bool = {{alias}}( -0.0 ) | ||
| false | ||
|
|
||
| See Also | ||
| -------- | ||
|
|
40 changes: 40 additions & 0 deletions
40
lib/node_modules/@stdlib/number/float16/base/assert/is-positive-zero/docs/types/index.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // TypeScript Version: 4.1 | ||
|
|
||
| /** | ||
| * Tests if a half-precision floating-point numeric value is positive zero. | ||
| * | ||
| * @param x - value to test | ||
| * @returns boolean indicating whether the value is positive zero | ||
| * | ||
| * @example | ||
| * var bool = isPositiveZero( 0.0 ); | ||
| * // returns true | ||
| * | ||
| * @example | ||
| * var bool = isPositiveZero( -0.0 ); | ||
| * // returns false | ||
| */ | ||
| declare function isPositiveZero( x: number ): boolean; | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| export = isPositiveZero; |
46 changes: 46 additions & 0 deletions
46
lib/node_modules/@stdlib/number/float16/base/assert/is-positive-zero/docs/types/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import isPositiveZero = require( './index' ); | ||
|
|
||
|
|
||
| // TESTS // | ||
|
|
||
| // The function returns a boolean... | ||
| { | ||
| isPositiveZero( 0 ); // $ExpectType boolean | ||
| isPositiveZero( -0 ); // $ExpectType boolean | ||
| isPositiveZero( 2 ); // $ExpectType boolean | ||
| } | ||
|
|
||
| // The compiler throws an error if the function is provided a value other than a number... | ||
| { | ||
| isPositiveZero( true ); // $ExpectError | ||
| isPositiveZero( false ); // $ExpectError | ||
| isPositiveZero( null ); // $ExpectError | ||
| isPositiveZero( undefined ); // $ExpectError | ||
| isPositiveZero( [] ); // $ExpectError | ||
| isPositiveZero( {} ); // $ExpectError | ||
| isPositiveZero( ( x: number ): number => x ); // $ExpectError | ||
| } | ||
|
|
||
| // The compiler throws an error if the function is provided an unsupported number of arguments... | ||
| { | ||
| isPositiveZero(); // $ExpectError | ||
| isPositiveZero( undefined, 123 ); // $ExpectError | ||
| } |
36 changes: 36 additions & 0 deletions
36
lib/node_modules/@stdlib/number/float16/base/assert/is-positive-zero/examples/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| var isPositiveZero = require( './../lib' ); | ||
|
|
||
| console.log( isPositiveZero( 0.0 ) ); | ||
| // => true | ||
|
|
||
| console.log( isPositiveZero( -0.0 ) ); | ||
| // => false | ||
|
|
||
| console.log( isPositiveZero( 5.0 ) ); | ||
| // => false | ||
|
|
||
| console.log( isPositiveZero( -1.0 ) ); | ||
| // => false | ||
|
|
||
| console.log( isPositiveZero( NaN ) ); | ||
| // => false |
43 changes: 43 additions & 0 deletions
43
lib/node_modules/@stdlib/number/float16/base/assert/is-positive-zero/lib/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Test if a half-precision floating-point numeric value is positive zero. | ||
| * | ||
| * @module @stdlib/number/float16/base/assert/is-positive-zero | ||
| * | ||
| * @example | ||
| * var isPositiveZero = require( '@stdlib/number/float16/base/assert/is-positive-zero' ); | ||
| * | ||
| * var bool = isPositiveZero( 0.0 ); | ||
| * // returns true | ||
| * | ||
| * bool = isPositiveZero( -0.0 ); | ||
| * // returns false | ||
| */ | ||
|
|
||
| // MODULES // | ||
|
|
||
| var main = require( './main.js' ); | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| module.exports = main; |
49 changes: 49 additions & 0 deletions
49
lib/node_modules/@stdlib/number/float16/base/assert/is-positive-zero/lib/main.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 The Stdlib Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| // MODULES // | ||
|
|
||
| var PINF = require( '@stdlib/constants/float32/pinf' ); | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| /** | ||
| * Tests if a half-precision floating-point numeric value is positive zero. | ||
| * | ||
| * @param {number} x - value to test | ||
| * @returns {boolean} boolean indicating whether the value is positive zero | ||
| * | ||
| * @example | ||
| * var bool = isPositiveZero( 0.0 ); | ||
| * // returns true | ||
| * | ||
| * @example | ||
| * var bool = isPositiveZero( -0.0 ); | ||
| * // returns false | ||
| */ | ||
| function isPositiveZero( x ) { | ||
| return (x === 0.0 && 1.0/x === PINF); | ||
| } | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| module.exports = isPositiveZero; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.