|
21 | 21 | /* eslint-disable max-lines */ |
22 | 22 |
|
23 | 23 | import isAlmostEqual = require( '@stdlib/number/float64/base/assert/is-almost-equal' ); |
| 24 | +import isAlmostSameValue = require( '@stdlib/number/float64/base/assert/is-almost-same-value' ); |
24 | 25 | import isSameValue = require( '@stdlib/number/float64/base/assert/is-same-value' ); |
25 | 26 | import isSameValueZero = require( '@stdlib/number/float64/base/assert/is-same-value-zero' ); |
26 | 27 |
|
@@ -67,6 +68,44 @@ interface Namespace { |
67 | 68 | */ |
68 | 69 | isAlmostEqual: typeof isAlmostEqual; |
69 | 70 |
|
| 71 | + /** |
| 72 | + * Tests if two double-precision floating-point numbers are approximately the same value within a specified number of ULPs (units in the last place). |
| 73 | + * |
| 74 | + * ## Notes |
| 75 | + * |
| 76 | + * - The function differs from the `===` operator in that the function treats `-0` and `+0` as distinct and `NaNs` as the same. |
| 77 | + * |
| 78 | + * @param a - first input value |
| 79 | + * @param b - second input value |
| 80 | + * @param maxULP - maximum allowed ULP difference |
| 81 | + * @returns boolean indicating whether two double-precision floating-point numbers are approximately the same value within a specified number of ULPs |
| 82 | + * |
| 83 | + * @example |
| 84 | + * var EPS = require( '@stdlib/constants/float64/eps' ); |
| 85 | + * |
| 86 | + * var bool = ns.isAlmostSameValue( 1.0, 1.0+EPS, 1 ); |
| 87 | + * // returns true |
| 88 | + * |
| 89 | + * bool = ns.isAlmostSameValue( 1.0+EPS, 1.0, 1 ); |
| 90 | + * // returns true |
| 91 | + * |
| 92 | + * bool = ns.isAlmostSameValue( 1.0, 1.0+EPS+EPS, 1 ); |
| 93 | + * // returns false |
| 94 | + * |
| 95 | + * bool = ns.isAlmostSameValue( 1.0, 1.0+EPS, 0 ); |
| 96 | + * // returns false |
| 97 | + * |
| 98 | + * bool = ns.isAlmostSameValue( 0.0, -0.0, 0 ); |
| 99 | + * // returns false |
| 100 | + * |
| 101 | + * bool = ns.isAlmostSameValue( 1.0, NaN, 1 ); |
| 102 | + * // returns false |
| 103 | + * |
| 104 | + * bool = ns.isAlmostSameValue( NaN, NaN, 1 ); |
| 105 | + * // returns true |
| 106 | + */ |
| 107 | + isAlmostSameValue: typeof isAlmostSameValue; |
| 108 | + |
70 | 109 | /** |
71 | 110 | * Tests if two double-precision floating-point numbers are the same value. |
72 | 111 | * |
|
0 commit comments