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 luoyonggang@gmail.com
This commit is contained in:
Yonggang Luo 2021-01-16 20:25:41 +00:00 committed by GitHub
parent 3ce4dce805
commit abaf9637d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,11 @@ function isSameZero (x, y)
return x === 0 && (1 / x) === (1 / y);
}
function approxEq (x, y)
{
return Math.abs(x - y) <= Number.EPSILON * 2
}
assert(isNaN(Math.cbrt(NaN)));
assert(isSameZero(Math.cbrt(p_zero), p_zero));
assert(isSameZero(Math.cbrt(n_zero), n_zero));
@ -29,5 +34,5 @@ assert(Math.cbrt(Number.NEGATIVE_INFINITY) === Number.NEGATIVE_INFINITY);
assert(Math.cbrt(1.0) === 1.0);
assert(Math.cbrt(-1.0) === -1.0);
// assert(Math.cbrt(27.0) === 3.0); // FIXME: unstable, depending on compiler and libm
assert(Math.cbrt(0.001) === 0.1);
assert(approxEq(Math.cbrt(27.0), 3.0));
assert(approxEq(Math.cbrt(0.001), 0.1));