Skip to content

Commit abaf963

Browse files
authored
Use approxEq to judge double compare in math-cbrt.js (#4483)
Number.EPSILON used as maximal differences. JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
1 parent 3ce4dce commit abaf963

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tests/jerry/es.next/math-cbrt.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ function isSameZero (x, y)
2020
return x === 0 && (1 / x) === (1 / y);
2121
}
2222

23+
function approxEq (x, y)
24+
{
25+
return Math.abs(x - y) <= Number.EPSILON * 2
26+
}
27+
2328
assert(isNaN(Math.cbrt(NaN)));
2429
assert(isSameZero(Math.cbrt(p_zero), p_zero));
2530
assert(isSameZero(Math.cbrt(n_zero), n_zero));
@@ -29,5 +34,5 @@ assert(Math.cbrt(Number.NEGATIVE_INFINITY) === Number.NEGATIVE_INFINITY);
2934
assert(Math.cbrt(1.0) === 1.0);
3035
assert(Math.cbrt(-1.0) === -1.0);
3136

32-
// assert(Math.cbrt(27.0) === 3.0); // FIXME: unstable, depending on compiler and libm
33-
assert(Math.cbrt(0.001) === 0.1);
37+
assert(approxEq(Math.cbrt(27.0), 3.0));
38+
assert(approxEq(Math.cbrt(0.001), 0.1));

0 commit comments

Comments
 (0)