Skip to content

Commit 88de30d

Browse files
committed
Auto-generated commit
1 parent e5ed4da commit 88de30d

File tree

12 files changed

+891
-0
lines changed

12 files changed

+891
-0
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
### Features
1212

13+
- [`b380d14`](https://github.com/stdlib-js/stdlib/commit/b380d1437365ca578efef334911b78cdf84a9e4a) - add `hasSplitSymbolSupport` to namespace
14+
- [`7108f43`](https://github.com/stdlib-js/stdlib/commit/7108f43f0b9253bd6a838e2eeef53955b90c8c6f) - add `isAlmostSameValue` to namespace
15+
- [`c90efc0`](https://github.com/stdlib-js/stdlib/commit/c90efc01f6333a512c611d778fabaae53913374c) - add `assert/is-almost-same-value`
1316
- [`e8ade3f`](https://github.com/stdlib-js/stdlib/commit/e8ade3f578cfe949f5295a63f2d26fabe7e8928f) - update `assert` TypeScript declarations
1417
- [`38e4338`](https://github.com/stdlib-js/stdlib/commit/38e433821d47feaeb98a76eba305d54c45371c20) - add `assert/has-split-symbol-support` [(#8476)](https://github.com/stdlib-js/stdlib/pull/8476)
1518
- [`62c17c8`](https://github.com/stdlib-js/stdlib/commit/62c17c82a0219e456eeb05d3b0a0d6ca17ad09ed) - add `hasToPrimitiveSymbolSupport` to namespace
@@ -141,6 +144,10 @@ A total of 27 issues were closed in this release:
141144

142145
<details>
143146

147+
- [`6422dd2`](https://github.com/stdlib-js/stdlib/commit/6422dd250a665bdf380af258abd3f35091150a87) - **style:** disable lint rule _(by Athan Reines)_
148+
- [`b380d14`](https://github.com/stdlib-js/stdlib/commit/b380d1437365ca578efef334911b78cdf84a9e4a) - **feat:** add `hasSplitSymbolSupport` to namespace _(by Athan Reines)_
149+
- [`7108f43`](https://github.com/stdlib-js/stdlib/commit/7108f43f0b9253bd6a838e2eeef53955b90c8c6f) - **feat:** add `isAlmostSameValue` to namespace _(by Athan Reines)_
150+
- [`c90efc0`](https://github.com/stdlib-js/stdlib/commit/c90efc01f6333a512c611d778fabaae53913374c) - **feat:** add `assert/is-almost-same-value` _(by Athan Reines)_
144151
- [`d5688cf`](https://github.com/stdlib-js/stdlib/commit/d5688cfd992eeaaeefc3f570ddfe516e2a47d217) - **refactor:** use base assertion utility _(by Athan Reines)_
145152
- [`01e0c7f`](https://github.com/stdlib-js/stdlib/commit/01e0c7fe9eadd0c2a0c5bc290675d6a5e325980c) - **docs:** fix empty notes section _(by Athan Reines)_
146153
- [`e3e3d25`](https://github.com/stdlib-js/stdlib/commit/e3e3d254f2f8a639cd59482726b9286ddb31b274) - **chore:** fix JavaScript lint errors [(#8897)](https://github.com/stdlib-js/stdlib/pull/8897) _(by Rohit R Bhat, Athan Reines)_

is-almost-same-value/README.md

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
# isAlmostSameValue
22+
23+
> Test if two arguments are approximately the same value within a specified number of ULPs (units in the last place).
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
31+
```
32+
33+
#### isAlmostSameValue( a, b, maxULP )
34+
35+
Tests if two arguments are approximately the same value within a specified number of ULPs (units in the last place).
36+
37+
```javascript
38+
var EPS = require( '@stdlib/constants/float64/eps' );
39+
40+
var bool = isAlmostSameValue( 1.0, 1.0+EPS, 1 );
41+
// returns true
42+
43+
bool = isAlmostSameValue( '', '', 0 );
44+
// returns true
45+
46+
bool = isAlmostSameValue( {}, {}, 1 );
47+
// returns false
48+
```
49+
50+
In contrast to the strict equality operator `===`, the function distinguishes between `+0` and `-0` and treats `NaNs` as the same value.
51+
52+
```javascript
53+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
54+
55+
var bool = isAlmostSameValue( NaN, 1.0, 1 );
56+
// returns false
57+
58+
bool = isAlmostSameValue( NaN, NaN, 1 );
59+
// returns true
60+
61+
var z1 = new Complex128( NaN, 3.0 );
62+
var z2 = new Complex128( 1.0, 3.0 );
63+
64+
bool = isAlmostSameValue( z1, z2, 1 );
65+
// returns false
66+
67+
z1 = new Complex128( NaN, NaN );
68+
z2 = new Complex128( NaN, NaN );
69+
70+
bool = isAlmostSameValue( z1, z2, 1 );
71+
// returns true
72+
73+
bool = isAlmostSameValue( 0.0, -0.0, 0 );
74+
// returns false
75+
76+
z1 = new Complex128( 0.0, 0.0 );
77+
z2 = new Complex128( -0.0, -0.0 );
78+
79+
bool = isAlmostSameValue( z1, z2, 0 );
80+
// returns false
81+
```
82+
83+
</section>
84+
85+
<!-- /.usage -->
86+
87+
<section class="notes">
88+
89+
## Notes
90+
91+
- The function implements the [SameValue Algorithm][ecma-262-same-value-algorithm] as specified in ECMAScript 5.
92+
93+
</section>
94+
95+
<!-- /.notes -->
96+
97+
<section class="examples">
98+
99+
## Examples
100+
101+
<!-- eslint no-undef: "error" -->
102+
103+
```javascript
104+
var EPS = require( '@stdlib/constants/float64/eps' );
105+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
106+
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
107+
108+
console.log( isAlmostSameValue( true, true, 0 ) );
109+
// => true
110+
111+
console.log( isAlmostSameValue( true, false, 1 ) );
112+
// => false
113+
114+
console.log( isAlmostSameValue( 'beep', 'beep', 1 ) );
115+
// => true
116+
117+
console.log( isAlmostSameValue( 1.0, 1.0+EPS, 1 ) );
118+
// => true
119+
120+
console.log( isAlmostSameValue( null, null, 0 ) );
121+
// => true
122+
123+
console.log( isAlmostSameValue( 0.0, -0.0, 0 ) );
124+
// => false
125+
126+
console.log( isAlmostSameValue( NaN, NaN, 1 ) );
127+
// => true
128+
129+
var z1 = new Complex128( 1.0, 3.0+EPS );
130+
var z2 = new Complex128( 1.0+EPS, 3.0 );
131+
console.log( isAlmostSameValue( z1, z2, 1 ) );
132+
// => true
133+
134+
console.log( isAlmostSameValue( {}, {}, 1 ) );
135+
// => false
136+
137+
console.log( isAlmostSameValue( [], [], 1 ) );
138+
// => false
139+
140+
console.log( isAlmostSameValue( isAlmostSameValue, isAlmostSameValue, 0 ) );
141+
// => true
142+
```
143+
144+
</section>
145+
146+
<!-- /.examples -->
147+
148+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
149+
150+
<section class="related">
151+
152+
</section>
153+
154+
<!-- /.related -->
155+
156+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
157+
158+
<section class="links">
159+
160+
[ecma-262-same-value-algorithm]: http://ecma-international.org/ecma-262/5.1/#sec-9.12
161+
162+
<!-- <related-links> -->
163+
164+
<!-- </related-links> -->
165+
166+
</section>
167+
168+
<!-- /.links -->
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
/* eslint-disable no-empty-function */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var bench = require( '@stdlib/bench' );
26+
var isBoolean = require( './../../is-boolean' ).isPrimitive;
27+
var pkg = require( './../package.json' ).name;
28+
var isAlmostSameValue = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg, function benchmark( b ) {
34+
var values;
35+
var bool;
36+
var v;
37+
var i;
38+
39+
values = [
40+
'',
41+
'5',
42+
0,
43+
5,
44+
NaN,
45+
true,
46+
false,
47+
null,
48+
void 0,
49+
[],
50+
{},
51+
new RegExp( '.*' ), // eslint-disable-line prefer-regex-literals
52+
new Date(),
53+
function noop() {}
54+
];
55+
56+
b.tic();
57+
for ( i = 0; i < b.iterations; i++ ) {
58+
v = values[ i%values.length ];
59+
bool = isAlmostSameValue( v, v, 1 );
60+
if ( typeof bool !== 'boolean' ) {
61+
b.fail( 'should return a boolean' );
62+
}
63+
}
64+
b.toc();
65+
if ( !isBoolean( bool ) ) {
66+
b.fail( 'should return a boolean' );
67+
}
68+
b.pass( 'benchmark finished' );
69+
b.end();
70+
});

is-almost-same-value/docs/repl.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
{{alias}}( a, b, maxULP )
3+
Tests if two arguments are approximately the same value within a specified
4+
number of ULPs (units in the last place).
5+
6+
The function differs from the `===` operator in that the function treats
7+
`-0` and `+0` as distinct and `NaNs` as the same.
8+
9+
Parameters
10+
----------
11+
a: any
12+
First input value.
13+
14+
b: any
15+
Second input value.
16+
17+
maxULP: integer
18+
Maximum allowed ULP difference.
19+
20+
Returns
21+
-------
22+
bool: boolean
23+
Boolean indicating whether two arguments are approximately the same
24+
value within a specified number of ULPs.
25+
26+
Examples
27+
--------
28+
> var bool = {{alias}}( true, true, 0 )
29+
true
30+
> bool = {{alias}}( 1+{{alias:@stdlib/constants/float64/eps}}, 1, 1 )
31+
true
32+
> bool = {{alias}}( {}, {}, 1 )
33+
false
34+
> bool = {{alias}}( 0.0, -0.0, 0 )
35+
false
36+
> bool = {{alias}}( NaN, 1.0, 1 )
37+
false
38+
> bool = {{alias}}( NaN, NaN, 0 )
39+
true
40+
41+
See Also
42+
--------
43+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 two arguments are approximately the same value within a specified number of ULPs (units in the last place).
23+
*
24+
* ## Notes
25+
*
26+
* - The function differs from the `===` operator in that the function treats `-0` and `+0` as distinct and `NaNs` as the same.
27+
*
28+
* @param a - first input value
29+
* @param b - second input value
30+
* @param maxULP - maximum allowed ULP difference
31+
* @returns boolean indicating whether two arguments are approximately the same value within a specified number of ULPs
32+
*
33+
* @example
34+
* var EPS = require( '@stdlib/constants/float64/eps' );
35+
*
36+
* var bool = isAlmostSameValue( 1.0, 1.0+EPS, 0 );
37+
* // returns false
38+
*
39+
* bool = isAlmostSameValue( 1.0, 1.0+EPS, 1 );
40+
* // returns true
41+
*
42+
* bool = isAlmostSameValue( {}, {}, 0 );
43+
* // returns false
44+
*
45+
* bool = isAlmostSameValue( -0.0, 0.0, 0 );
46+
* // returns false
47+
*
48+
* bool = isAlmostSameValue( NaN, NaN, 0 );
49+
* // returns true
50+
*
51+
* bool = isAlmostSameValue( [], [], 1 );
52+
* // returns false
53+
*/
54+
declare function isAlmostSameValue( a: any, b: any, maxULP: number ): boolean;
55+
56+
57+
// EXPORTS //
58+
59+
export = isAlmostSameValue;

0 commit comments

Comments
 (0)