Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | loadRelativeToScript("../../../tests/ecma_6/Math/shell.js"); |
michael@0 | 2 | |
michael@0 | 3 | for (var i = -20; i < 20; i++) { |
michael@0 | 4 | assertEq(Math.hypot(+0, i), Math.abs(i)); |
michael@0 | 5 | assertEq(Math.hypot(-0, i), Math.abs(i)); |
michael@0 | 6 | } |
michael@0 | 7 | |
michael@0 | 8 | // The implementation must avoid underlow. |
michael@0 | 9 | // The implementation must avoid overflow, where possible. |
michael@0 | 10 | // The implementation must minimise rounding errors. |
michael@0 | 11 | |
michael@0 | 12 | assertNear(Math.hypot(1e-300, 1e-300), 1.414213562373095e-300); |
michael@0 | 13 | assertNear(Math.hypot(1e-300, 1e-300, 1e-300), 1.732050807568877e-300); |
michael@0 | 14 | |
michael@0 | 15 | assertNear(Math.hypot(1e-3, 1e-3, 1e-3), 0.0017320508075688772); |
michael@0 | 16 | |
michael@0 | 17 | assertNear(Math.hypot(1e300, 1e300), 1.4142135623730952e+300); |
michael@0 | 18 | assertNear(Math.hypot(1e100, 1e200, 1e300), 1e300); |
michael@0 | 19 | |
michael@0 | 20 | assertNear(Math.hypot(1e3, 1e-3), 1000.0000000005); |
michael@0 | 21 | assertNear(Math.hypot(1e-300, 1e300), 1e300); |
michael@0 | 22 | assertNear(Math.hypot(1e3, 1e-3, 1e3, 1e-3), 1414.2135623738021555); |
michael@0 | 23 | |
michael@0 | 24 | for (var i = 1, j = 1; i < 2; i += 0.05, j += 0.05) |
michael@0 | 25 | assertNear(Math.hypot(i, j), Math.sqrt(i * i + j * j)); |