OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 assertEquals(1, Math.max(+0, -0, +1)); | 108 assertEquals(1, Math.max(+0, -0, +1)); |
109 assertEquals(1, Math.max(+1, +0, -0)); | 109 assertEquals(1, Math.max(+1, +0, -0)); |
110 assertEquals(1, Math.max(+0, +1, -0)); | 110 assertEquals(1, Math.max(+0, +1, -0)); |
111 assertEquals(1, Math.max(-0, +1, +0)); | 111 assertEquals(1, Math.max(-0, +1, +0)); |
112 assertEquals(NaN, Math.max('oxen')); | 112 assertEquals(NaN, Math.max('oxen')); |
113 assertEquals(NaN, Math.max('oxen', 1)); | 113 assertEquals(NaN, Math.max('oxen', 1)); |
114 assertEquals(NaN, Math.max(1, 'oxen')); | 114 assertEquals(NaN, Math.max(1, 'oxen')); |
115 | 115 |
116 assertEquals(Infinity, 1/Math.max(ZERO, -0)); | 116 assertEquals(Infinity, 1/Math.max(ZERO, -0)); |
117 assertEquals(Infinity, 1/Math.max(-0, ZERO)); | 117 assertEquals(Infinity, 1/Math.max(-0, ZERO)); |
| 118 |
| 119 function run(crankshaft_test) { |
| 120 crankshaft_test(1); |
| 121 crankshaft_test(1); |
| 122 %OptimizeFunctionOnNextCall(crankshaft_test); |
| 123 crankshaft_test(-0); |
| 124 } |
| 125 |
| 126 function crankshaft_test_1(arg) { |
| 127 var v1 = 1; |
| 128 var v2 = 5; |
| 129 var v3 = 1.5; |
| 130 var v4 = 5.5; |
| 131 var v5 = 2; |
| 132 var v6 = 6; |
| 133 var v7 = 0; |
| 134 var v8 = -0; |
| 135 |
| 136 var v9 = 9.9; |
| 137 var v0 = 10.1; |
| 138 // Integer32 representation. |
| 139 assertEquals(v2, Math.max(v1++, v2++)); |
| 140 assertEquals(v1, Math.min(v1++, v2++)); |
| 141 // Tagged representation. |
| 142 assertEquals(v4, Math.max(v3, v4)); |
| 143 assertEquals(v3, Math.min(v3, v4)); |
| 144 assertEquals(v6, Math.max(v5, v6)); |
| 145 assertEquals(v5, Math.min(v5, v6)); |
| 146 // Double representation. |
| 147 assertEquals(v0, Math.max(v0++, v9++)); |
| 148 assertEquals(v9, Math.min(v0++, v9++)); |
| 149 // Minus zero. |
| 150 assertEquals(Infinity, 1/Math.max(v7, v8)); |
| 151 assertEquals(-Infinity, 1/Math.min(v7, v8)); |
| 152 // NaN. |
| 153 assertEquals(NaN, Math.max(NaN, v8)); |
| 154 assertEquals(NaN, Math.min(NaN, v9)); |
| 155 assertEquals(NaN, Math.max(v8, NaN)); |
| 156 assertEquals(NaN, Math.min(v9, NaN)); |
| 157 // Minus zero as Integer32. |
| 158 assertEquals((arg === -0) ? -Infinity : 1, 1/Math.min(arg, v2)); |
| 159 } |
| 160 |
| 161 run(crankshaft_test_1); |
| 162 |
| 163 function crankshaft_test_2() { |
| 164 var v9 = {}; |
| 165 v9.valueOf = function() { return 6; } |
| 166 // Deopt expected due to non-heapnumber objects. |
| 167 assertEquals(6, Math.min(v9, 12)); |
| 168 } |
| 169 |
| 170 run(crankshaft_test_2); |
| 171 |
| 172 // Test overriding Math.min and Math.max |
| 173 Math.min = function(a, b) { return a + b; } |
| 174 Math.max = function(a, b) { return a - b; } |
| 175 |
| 176 function crankshaft_test_3() { |
| 177 assertEquals(8, Math.min(3, 5)); |
| 178 assertEquals(3, Math.max(5, 2)); |
| 179 } |
| 180 |
| 181 run(crankshaft_test_3); |
OLD | NEW |