js/src/jit-test/tests/basic/hypot-approx.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/basic/hypot-approx.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,25 @@
     1.4 +loadRelativeToScript("../../../tests/ecma_6/Math/shell.js");
     1.5 +
     1.6 +for (var i = -20; i < 20; i++) {
     1.7 +    assertEq(Math.hypot(+0, i), Math.abs(i));
     1.8 +    assertEq(Math.hypot(-0, i), Math.abs(i));
     1.9 +}
    1.10 +
    1.11 +// The implementation must avoid underlow.
    1.12 +// The implementation must avoid overflow, where possible.
    1.13 +// The implementation must minimise rounding errors.
    1.14 +
    1.15 +assertNear(Math.hypot(1e-300, 1e-300), 1.414213562373095e-300);
    1.16 +assertNear(Math.hypot(1e-300, 1e-300, 1e-300), 1.732050807568877e-300);
    1.17 +
    1.18 +assertNear(Math.hypot(1e-3, 1e-3, 1e-3), 0.0017320508075688772);
    1.19 +
    1.20 +assertNear(Math.hypot(1e300, 1e300), 1.4142135623730952e+300);
    1.21 +assertNear(Math.hypot(1e100, 1e200, 1e300), 1e300);
    1.22 +
    1.23 +assertNear(Math.hypot(1e3, 1e-3), 1000.0000000005);
    1.24 +assertNear(Math.hypot(1e-300, 1e300), 1e300);
    1.25 +assertNear(Math.hypot(1e3, 1e-3, 1e3, 1e-3), 1414.2135623738021555);
    1.26 +
    1.27 +for (var i = 1, j = 1; i < 2; i += 0.05, j += 0.05)
    1.28 +    assertNear(Math.hypot(i, j), Math.sqrt(i * i + j * j));

mercurial