1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_6/Math/trunc.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,50 @@ 1.4 +// If x is NaN, the result is NaN. 1.5 +assertEq(Math.trunc(NaN), NaN); 1.6 + 1.7 +// If x is −0, the result is −0. 1.8 +assertEq(Math.trunc(-0), -0); 1.9 + 1.10 +// If x is +0, the result is +0. 1.11 +assertEq(Math.trunc(+0), +0); 1.12 + 1.13 +// If x is +∞, the result is +∞. 1.14 +assertEq(Math.trunc(Infinity), Infinity); 1.15 + 1.16 +// If x is −∞, the result is −∞. 1.17 +assertEq(Math.trunc(-Infinity), -Infinity); 1.18 + 1.19 +// Other boundary cases. 1.20 +var MAX_NONINTEGER_VALUE = 4503599627370495.5; 1.21 +var TRUNC_MAX_NONINTEGER_VALUE = 4503599627370495; 1.22 + 1.23 +assertEq(Math.trunc(Number.MIN_VALUE), +0); 1.24 +assertEq(Math.trunc(ONE_MINUS_EPSILON), +0); 1.25 +assertEq(Math.trunc(ONE_PLUS_EPSILON), 1); 1.26 +assertEq(Math.trunc(MAX_NONINTEGER_VALUE), TRUNC_MAX_NONINTEGER_VALUE); 1.27 +assertEq(Math.trunc(Number.MAX_VALUE), Number.MAX_VALUE); 1.28 + 1.29 +assertEq(Math.trunc(-Number.MIN_VALUE), -0); 1.30 +assertEq(Math.trunc(-ONE_MINUS_EPSILON), -0); 1.31 +assertEq(Math.trunc(-ONE_PLUS_EPSILON), -1); 1.32 +assertEq(Math.trunc(-MAX_NONINTEGER_VALUE), -TRUNC_MAX_NONINTEGER_VALUE); 1.33 +assertEq(Math.trunc(-Number.MAX_VALUE), -Number.MAX_VALUE); 1.34 + 1.35 +// Other cases. 1.36 +for (var i = 1, f = 1.1; i < 20; i++, f += 1.0) 1.37 + assertEq(Math.trunc(f), i); 1.38 + 1.39 +for (var i = -1, f = -1.1; i > -20; i--, f -= 1.0) 1.40 + assertEq(Math.trunc(f), i); 1.41 + 1.42 +assertEq(Math.trunc(1e40 + 0.5), 1e40); 1.43 + 1.44 +assertEq(Math.trunc(1e300), 1e300); 1.45 +assertEq(Math.trunc(-1e300), -1e300); 1.46 +assertEq(Math.trunc(1e-300), 0); 1.47 +assertEq(Math.trunc(-1e-300), -0); 1.48 + 1.49 +assertEq(Math.trunc(+0.9999), +0); 1.50 +assertEq(Math.trunc(-0.9999), -0); 1.51 + 1.52 + 1.53 +reportCompare(0, 0, "ok");