js/src/tests/ecma_6/Math/trunc.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:487249f11fdc
1 // If x is NaN, the result is NaN.
2 assertEq(Math.trunc(NaN), NaN);
3
4 // If x is −0, the result is −0.
5 assertEq(Math.trunc(-0), -0);
6
7 // If x is +0, the result is +0.
8 assertEq(Math.trunc(+0), +0);
9
10 // If x is +∞, the result is +∞.
11 assertEq(Math.trunc(Infinity), Infinity);
12
13 // If x is −∞, the result is −∞.
14 assertEq(Math.trunc(-Infinity), -Infinity);
15
16 // Other boundary cases.
17 var MAX_NONINTEGER_VALUE = 4503599627370495.5;
18 var TRUNC_MAX_NONINTEGER_VALUE = 4503599627370495;
19
20 assertEq(Math.trunc(Number.MIN_VALUE), +0);
21 assertEq(Math.trunc(ONE_MINUS_EPSILON), +0);
22 assertEq(Math.trunc(ONE_PLUS_EPSILON), 1);
23 assertEq(Math.trunc(MAX_NONINTEGER_VALUE), TRUNC_MAX_NONINTEGER_VALUE);
24 assertEq(Math.trunc(Number.MAX_VALUE), Number.MAX_VALUE);
25
26 assertEq(Math.trunc(-Number.MIN_VALUE), -0);
27 assertEq(Math.trunc(-ONE_MINUS_EPSILON), -0);
28 assertEq(Math.trunc(-ONE_PLUS_EPSILON), -1);
29 assertEq(Math.trunc(-MAX_NONINTEGER_VALUE), -TRUNC_MAX_NONINTEGER_VALUE);
30 assertEq(Math.trunc(-Number.MAX_VALUE), -Number.MAX_VALUE);
31
32 // Other cases.
33 for (var i = 1, f = 1.1; i < 20; i++, f += 1.0)
34 assertEq(Math.trunc(f), i);
35
36 for (var i = -1, f = -1.1; i > -20; i--, f -= 1.0)
37 assertEq(Math.trunc(f), i);
38
39 assertEq(Math.trunc(1e40 + 0.5), 1e40);
40
41 assertEq(Math.trunc(1e300), 1e300);
42 assertEq(Math.trunc(-1e300), -1e300);
43 assertEq(Math.trunc(1e-300), 0);
44 assertEq(Math.trunc(-1e-300), -0);
45
46 assertEq(Math.trunc(+0.9999), +0);
47 assertEq(Math.trunc(-0.9999), -0);
48
49
50 reportCompare(0, 0, "ok");

mercurial