diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/Math/pow-approx-pow10.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Math/pow-approx-pow10.js')
-rw-r--r-- | js/src/tests/non262/Math/pow-approx-pow10.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/js/src/tests/non262/Math/pow-approx-pow10.js b/js/src/tests/non262/Math/pow-approx-pow10.js new file mode 100644 index 0000000000..c95eeab428 --- /dev/null +++ b/js/src/tests/non262/Math/pow-approx-pow10.js @@ -0,0 +1,51 @@ +if (typeof fdlibm === "undefined") { + var fdlibm = SpecialPowers.Cu.getJSTestingFunctions().fdlibm; +} + +const f64 = new Float64Array(1); +const ui64 = new BigUint64Array(f64.buffer); + +function toBits(n) { + f64[0] = n; + return ui64[0]; +} + +function errorInULP(actual, expected) { + // Handle NaN and +0/-0. + if (Object.is(actual, expected)) { + return 0; + } + + let x = toBits(actual); + let y = toBits(expected); + return x <= y ? Number(y - x) : Number(x - y); +} + +const maxExponent = Math.trunc(Math.log10(Number.MAX_VALUE)); +const minExponent = Math.trunc(Math.log10(Number.MIN_VALUE)); + +assertEq(Math.pow(10, maxExponent + 1), Infinity); +assertEq(Math.pow(10, minExponent - 1), 0); + +// Ensure the error is less than 2 ULP when compared to fdlibm. +for (let i = minExponent; i <= maxExponent; ++i) { + let actual = Math.pow(10, i); + let expected = fdlibm.pow(10, i); + let error = errorInULP(actual, expected); + + assertEq(error < 2, true, + `${10} ** ${i}: ${actual} (${toBits(actual).toString(16)}) != ${expected} (${toBits(expected).toString(16)})`); +} + +// Ensure the error is less than 2 ULP when compared to parsed string |1ep|. +for (let i = minExponent; i <= maxExponent; ++i) { + let actual = Math.pow(10, i); + let expected = Number("1e" + i); + let error = errorInULP(actual, expected); + + assertEq(error < 2, true, + `${10} ** ${i}: ${actual} (${toBits(actual).toString(16)}) != ${expected} (${toBits(expected).toString(16)})`); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |