OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 if (arg2 > arg1) return arg2; | 124 if (arg2 > arg1) return arg2; |
125 if (arg1 > arg2) return arg1; | 125 if (arg1 > arg2) return arg1; |
126 if (arg1 == arg2) { | 126 if (arg1 == arg2) { |
127 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be | 127 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be |
128 // a Smi or a heap number. | 128 // a Smi or a heap number. |
129 return (arg1 == 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg2 : arg1; | 129 return (arg1 == 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg2 : arg1; |
130 } | 130 } |
131 // All comparisons failed, one of the arguments must be NaN. | 131 // All comparisons failed, one of the arguments must be NaN. |
132 return 0/0; // Compiler constant-folds this to NaN. | 132 return 0/0; // Compiler constant-folds this to NaN. |
133 } | 133 } |
134 if (length == 0) { | 134 var r = -1/0; // Compiler constant-folds this to -Infinity. |
135 return -1/0; // Compiler constant-folds this to -Infinity. | 135 for (var i = 0; i < length; i++) { |
136 } | |
137 var r = arg1; | |
138 if (!IS_NUMBER(r)) r = NonNumberToNumber(r); | |
139 if (NUMBER_IS_NAN(r)) return r; | |
140 for (var i = 1; i < length; i++) { | |
141 var n = %_Arguments(i); | 136 var n = %_Arguments(i); |
142 if (!IS_NUMBER(n)) n = NonNumberToNumber(n); | 137 if (!IS_NUMBER(n)) n = NonNumberToNumber(n); |
143 if (NUMBER_IS_NAN(n)) return n; | |
144 // Make sure +0 is considered greater than -0. -0 is never a Smi, +0 can be | 138 // Make sure +0 is considered greater than -0. -0 is never a Smi, +0 can be |
145 // a Smi or heap number. | 139 // a Smi or heap number. |
146 if (n > r || (r == 0 && n == 0 && !%_IsSmi(r) && 1 / r < 0)) r = n; | 140 if (NUMBER_IS_NAN(n) || n > r || |
| 141 (r == 0 && n == 0 && !%_IsSmi(r) && 1 / r < 0)) { |
| 142 r = n; |
| 143 } |
147 } | 144 } |
148 return r; | 145 return r; |
149 } | 146 } |
150 | 147 |
151 // ECMA 262 - 15.8.2.12 | 148 // ECMA 262 - 15.8.2.12 |
152 function MathMin(arg1, arg2) { // length == 2 | 149 function MathMin(arg1, arg2) { // length == 2 |
153 var length = %_ArgumentsLength(); | 150 var length = %_ArgumentsLength(); |
154 if (length == 2) { | 151 if (length == 2) { |
155 if (!IS_NUMBER(arg1)) arg1 = NonNumberToNumber(arg1); | 152 if (!IS_NUMBER(arg1)) arg1 = NonNumberToNumber(arg1); |
156 if (!IS_NUMBER(arg2)) arg2 = NonNumberToNumber(arg2); | 153 if (!IS_NUMBER(arg2)) arg2 = NonNumberToNumber(arg2); |
157 if (arg2 > arg1) return arg1; | 154 if (arg2 > arg1) return arg1; |
158 if (arg1 > arg2) return arg2; | 155 if (arg1 > arg2) return arg2; |
159 if (arg1 == arg2) { | 156 if (arg1 == arg2) { |
160 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be | 157 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be |
161 // a Smi or a heap number. | 158 // a Smi or a heap number. |
162 return (arg1 == 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg1 : arg2; | 159 return (arg1 == 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg1 : arg2; |
163 } | 160 } |
164 // All comparisons failed, one of the arguments must be NaN. | 161 // All comparisons failed, one of the arguments must be NaN. |
165 return 0/0; // Compiler constant-folds this to NaN. | 162 return 0/0; // Compiler constant-folds this to NaN. |
166 } | 163 } |
167 if (length == 0) { | 164 var r = 1/0; // Compiler constant-folds this to Infinity. |
168 return 1/0; // Compiler constant-folds this to Infinity. | 165 for (var i = 0; i < length; i++) { |
169 } | |
170 var r = arg1; | |
171 if (!IS_NUMBER(r)) r = NonNumberToNumber(r); | |
172 if (NUMBER_IS_NAN(r)) return r; | |
173 for (var i = 1; i < length; i++) { | |
174 var n = %_Arguments(i); | 166 var n = %_Arguments(i); |
175 if (!IS_NUMBER(n)) n = NonNumberToNumber(n); | 167 if (!IS_NUMBER(n)) n = NonNumberToNumber(n); |
176 if (NUMBER_IS_NAN(n)) return n; | |
177 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be a | 168 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be a |
178 // Smi or a heap number. | 169 // Smi or a heap number. |
179 if (n < r || (r == 0 && n == 0 && !%_IsSmi(n) && 1 / n < 0)) r = n; | 170 if (NUMBER_IS_NAN(n) || n < r || |
| 171 (r == 0 && n == 0 && !%_IsSmi(n) && 1 / n < 0)) { |
| 172 r = n; |
| 173 } |
180 } | 174 } |
181 return r; | 175 return r; |
182 } | 176 } |
183 | 177 |
184 // ECMA 262 - 15.8.2.13 | 178 // ECMA 262 - 15.8.2.13 |
185 function MathPow(x, y) { | 179 function MathPow(x, y) { |
186 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); | 180 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
187 if (!IS_NUMBER(y)) y = NonNumberToNumber(y); | 181 if (!IS_NUMBER(y)) y = NonNumberToNumber(y); |
188 return %_MathPow(x, y); | 182 return %_MathPow(x, y); |
189 } | 183 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 "sqrt", MathSqrt, | 274 "sqrt", MathSqrt, |
281 "tan", MathTan, | 275 "tan", MathTan, |
282 "atan2", MathAtan2, | 276 "atan2", MathAtan2, |
283 "pow", MathPow, | 277 "pow", MathPow, |
284 "max", MathMax, | 278 "max", MathMax, |
285 "min", MathMin | 279 "min", MathMin |
286 )); | 280 )); |
287 } | 281 } |
288 | 282 |
289 SetUpMath(); | 283 SetUpMath(); |
OLD | NEW |