OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2010 the V8 project authors. All rights reserved. | |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | |
28 // Flags: --max-new-space-size=262144 | |
29 | |
30 function test() { | |
31 assertEquals(0, Math.floor(0)); | |
Erik Corry
2010/09/20 11:56:50
This tests the Smi 0 but not the heap number 0. N
Vitaly Repeshko
2010/09/21 12:54:49
Done. I left the smi test case for completeness.
| |
32 assertEquals(-0, Math.floor(-0)); | |
Erik Corry
2010/09/20 11:56:50
0 == -0 so this test doesn't really work. You nee
Vitaly Repeshko
2010/09/21 12:54:49
Good catch! Fixed.
| |
33 assertEquals(Infinity, Math.floor(Infinity)); | |
34 assertEquals(-Infinity, Math.floor(-Infinity)); | |
35 assertNaN(Math.floor(NaN)); | |
36 | |
37 assertEquals(0, Math.floor(0.1)); | |
38 assertEquals(0, Math.floor(0.5)); | |
39 assertEquals(0, Math.floor(0.7)); | |
40 assertEquals(-1, Math.floor(-0.1)); | |
41 assertEquals(-1, Math.floor(-0.5)); | |
42 assertEquals(-1, Math.floor(-0.7)); | |
43 assertEquals(1, Math.floor(1)); | |
44 assertEquals(1, Math.floor(1.1)); | |
45 assertEquals(1, Math.floor(1.5)); | |
46 assertEquals(1, Math.floor(1.7)); | |
47 assertEquals(-1, Math.floor(-1)); | |
48 assertEquals(-2, Math.floor(-1.1)); | |
49 assertEquals(-2, Math.floor(-1.5)); | |
50 assertEquals(-2, Math.floor(-1.7)); | |
51 | |
52 assertEquals(0, Math.floor(Number.MIN_VALUE)); | |
53 assertEquals(-1, Math.floor(-Number.MIN_VALUE)); | |
54 assertEquals(Number.MAX_VALUE, Math.floor(Number.MAX_VALUE)); | |
55 assertEquals(-Number.MAX_VALUE, Math.floor(-Number.MAX_VALUE)); | |
56 assertEquals(Infinity, Math.floor(Infinity)); | |
57 assertEquals(-Infinity, Math.floor(-Infinity)); | |
58 | |
59 // 2^30 is a smi boundary. | |
60 var two_30 = 1 << 30; | |
Erik Corry
2010/09/20 11:56:50
It would be nice to pass this in as an argument so
Vitaly Repeshko
2010/09/21 12:54:49
There are actually some differences. But even if t
| |
61 | |
62 assertEquals(two_30, Math.floor(two_30)); | |
63 assertEquals(two_30, Math.floor(two_30 + 0.1)); | |
64 assertEquals(two_30, Math.floor(two_30 + 0.5)); | |
65 assertEquals(two_30, Math.floor(two_30 + 0.7)); | |
66 | |
67 assertEquals(two_30 - 1, Math.floor(two_30 - 1)); | |
68 assertEquals(two_30 - 1, Math.floor(two_30 - 1 + 0.1)); | |
69 assertEquals(two_30 - 1, Math.floor(two_30 - 1 + 0.5)); | |
70 assertEquals(two_30 - 1, Math.floor(two_30 - 1 + 0.7)); | |
71 | |
72 assertEquals(-two_30, Math.floor(-two_30)); | |
73 assertEquals(-two_30, Math.floor(-two_30 + 0.1)); | |
74 assertEquals(-two_30, Math.floor(-two_30 + 0.5)); | |
75 assertEquals(-two_30, Math.floor(-two_30 + 0.7)); | |
76 | |
77 assertEquals(-two_30 + 1, Math.floor(-two_30 + 1)); | |
78 assertEquals(-two_30 + 1, Math.floor(-two_30 + 1 + 0.1)); | |
79 assertEquals(-two_30 + 1, Math.floor(-two_30 + 1 + 0.5)); | |
80 assertEquals(-two_30 + 1, Math.floor(-two_30 + 1 + 0.7)); | |
81 | |
82 // 2^52 is a precision boundary. | |
83 var two_52 = (1 << 30) * (1 << 22); | |
84 | |
85 assertEquals(two_52, Math.floor(two_52)); | |
86 assertEquals(two_52, Math.floor(two_52 + 0.1)); | |
87 assertEquals(two_52, two_52 + 0.5); | |
88 assertEquals(two_52, Math.floor(two_52 + 0.5)); | |
89 assertEquals(two_52 + 1, two_52 + 0.7); | |
90 assertEquals(two_52 + 1, Math.floor(two_52 + 0.7)); | |
91 | |
92 assertEquals(two_52 - 1, Math.floor(two_52 - 1)); | |
93 assertEquals(two_52 - 1, Math.floor(two_52 - 1 + 0.1)); | |
94 assertEquals(two_52 - 1, Math.floor(two_52 - 1 + 0.5)); | |
95 assertEquals(two_52 - 1, Math.floor(two_52 - 1 + 0.7)); | |
96 | |
97 assertEquals(-two_52, Math.floor(-two_52)); | |
98 assertEquals(-two_52, Math.floor(-two_52 + 0.1)); | |
99 assertEquals(-two_52, Math.floor(-two_52 + 0.5)); | |
100 assertEquals(-two_52, Math.floor(-two_52 + 0.7)); | |
101 | |
102 assertEquals(-two_52 + 1, Math.floor(-two_52 + 1)); | |
103 assertEquals(-two_52 + 1, Math.floor(-two_52 + 1 + 0.1)); | |
104 assertEquals(-two_52 + 1, Math.floor(-two_52 + 1 + 0.5)); | |
105 assertEquals(-two_52 + 1, Math.floor(-two_52 + 1 + 0.7)); | |
106 } | |
107 | |
108 | |
109 // Test in a loop to cover the custom IC and GC-related issues. | |
110 for (var i = 0; i < 500; i++) { | |
111 test(); | |
112 } | |
OLD | NEW |