summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/hypot-approx.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/jit-test/tests/basic/hypot-approx.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jit-test/tests/basic/hypot-approx.js')
-rw-r--r--js/src/jit-test/tests/basic/hypot-approx.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/hypot-approx.js b/js/src/jit-test/tests/basic/hypot-approx.js
new file mode 100644
index 000000000..452e6c633
--- /dev/null
+++ b/js/src/jit-test/tests/basic/hypot-approx.js
@@ -0,0 +1,34 @@
+loadRelativeToScript("../../../tests/ecma_6/Math/shell.js");
+
+for (var i = -20; i < 20; i++) {
+ assertEq(Math.hypot(+0, i), Math.abs(i));
+ assertEq(Math.hypot(-0, i), Math.abs(i));
+}
+
+// The implementation must avoid underlow.
+// The implementation must avoid overflow, where possible.
+// The implementation must minimise rounding errors.
+
+assertNear(Math.hypot(1e-300, 1e-300), 1.414213562373095e-300);
+assertNear(Math.hypot(1e-300, 1e-300, 1e-300), 1.732050807568877e-300);
+
+assertNear(Math.hypot(1e-3, 1e-3, 1e-3), 0.0017320508075688772);
+
+assertNear(Math.hypot(1e300, 1e300), 1.4142135623730952e+300);
+assertNear(Math.hypot(1e100, 1e200, 1e300), 1e300);
+
+assertNear(Math.hypot(1e3, 1e-3), 1000.0000000005);
+assertNear(Math.hypot(1e-300, 1e300), 1e300);
+assertNear(Math.hypot(1e3, 1e-3, 1e3, 1e-3), 1414.2135623738021555);
+
+assertNear(Math.hypot(1e1, 1e2, 1e3), Math.sqrt(1e2 + 1e4 + 1e6));
+assertNear(Math.hypot(1e1, 1e2, 1e3, 1e4), Math.sqrt(1e2 + 1e4 + 1e6 + 1e8));
+
+for (var i = 1, j = 2; i < 2; i += 0.05, j += 0.05)
+ assertNear(Math.hypot(i, j), Math.sqrt(i * i + j * j));
+
+for (var i = 1, j = 2, k = 3; i < 2; i += 0.05, j += 0.05, k += 0.05)
+ assertNear(Math.hypot(i, j, k), Math.sqrt(i * i + j * j + k * k));
+
+for (var i = 1, j = 2, k = 3, l = 4; i < 2; i += 0.05, j += 0.05, k += 0.05, l += 0.5)
+ assertNear(Math.hypot(i, j, k, l), Math.sqrt(i * i + j * j + k * k + l * l));