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 (!IS_NUMBER(arg1)) arg1 = NonNumberToNumber(arg1); | 124 if (!IS_NUMBER(arg1)) arg1 = NonNumberToNumber(arg1); |
125 if (!IS_NUMBER(arg2)) arg2 = NonNumberToNumber(arg2); | 125 if (!IS_NUMBER(arg2)) arg2 = NonNumberToNumber(arg2); |
126 if (arg2 > arg1) return arg2; | 126 if (arg2 > arg1) return arg2; |
127 if (arg1 > arg2) return arg1; | 127 if (arg1 > arg2) return arg1; |
128 if (arg1 == arg2) { | 128 if (arg1 == arg2) { |
129 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be | 129 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be |
130 // a Smi or a heap number. | 130 // a Smi or a heap number. |
131 return (arg1 == 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg2 : arg1; | 131 return (arg1 == 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg2 : arg1; |
132 } | 132 } |
133 // All comparisons failed, one of the arguments must be NaN. | 133 // All comparisons failed, one of the arguments must be NaN. |
134 return 0/0; // Compiler constant-folds this to NaN. | 134 return NAN; |
135 } | 135 } |
136 var r = -1/0; // Compiler constant-folds this to -Infinity. | 136 var r = -INFINITY; |
137 for (var i = 0; i < length; i++) { | 137 for (var i = 0; i < length; i++) { |
138 var n = %_Arguments(i); | 138 var n = %_Arguments(i); |
139 if (!IS_NUMBER(n)) n = NonNumberToNumber(n); | 139 if (!IS_NUMBER(n)) n = NonNumberToNumber(n); |
140 // Make sure +0 is considered greater than -0. -0 is never a Smi, +0 can be | 140 // Make sure +0 is considered greater than -0. -0 is never a Smi, +0 can be |
141 // a Smi or heap number. | 141 // a Smi or heap number. |
142 if (NUMBER_IS_NAN(n) || n > r || | 142 if (NUMBER_IS_NAN(n) || n > r || |
143 (r == 0 && n == 0 && !%_IsSmi(r) && 1 / r < 0)) { | 143 (r == 0 && n == 0 && !%_IsSmi(r) && 1 / r < 0)) { |
144 r = n; | 144 r = n; |
145 } | 145 } |
146 } | 146 } |
147 return r; | 147 return r; |
148 } | 148 } |
149 | 149 |
150 // ECMA 262 - 15.8.2.12 | 150 // ECMA 262 - 15.8.2.12 |
151 function MathMin(arg1, arg2) { // length == 2 | 151 function MathMin(arg1, arg2) { // length == 2 |
152 var length = %_ArgumentsLength(); | 152 var length = %_ArgumentsLength(); |
153 if (length == 2) { | 153 if (length == 2) { |
154 if (!IS_NUMBER(arg1)) arg1 = NonNumberToNumber(arg1); | 154 if (!IS_NUMBER(arg1)) arg1 = NonNumberToNumber(arg1); |
155 if (!IS_NUMBER(arg2)) arg2 = NonNumberToNumber(arg2); | 155 if (!IS_NUMBER(arg2)) arg2 = NonNumberToNumber(arg2); |
156 if (arg2 > arg1) return arg1; | 156 if (arg2 > arg1) return arg1; |
157 if (arg1 > arg2) return arg2; | 157 if (arg1 > arg2) return arg2; |
158 if (arg1 == arg2) { | 158 if (arg1 == arg2) { |
159 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be | 159 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be |
160 // a Smi or a heap number. | 160 // a Smi or a heap number. |
161 return (arg1 == 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg1 : arg2; | 161 return (arg1 == 0 && !%_IsSmi(arg1) && 1 / arg1 < 0) ? arg1 : arg2; |
162 } | 162 } |
163 // All comparisons failed, one of the arguments must be NaN. | 163 // All comparisons failed, one of the arguments must be NaN. |
164 return 0/0; // Compiler constant-folds this to NaN. | 164 return NAN; |
165 } | 165 } |
166 var r = 1/0; // Compiler constant-folds this to Infinity. | 166 var r = INFINITY; |
167 for (var i = 0; i < length; i++) { | 167 for (var i = 0; i < length; i++) { |
168 var n = %_Arguments(i); | 168 var n = %_Arguments(i); |
169 if (!IS_NUMBER(n)) n = NonNumberToNumber(n); | 169 if (!IS_NUMBER(n)) n = NonNumberToNumber(n); |
170 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be a | 170 // Make sure -0 is considered less than +0. -0 is never a Smi, +0 can be a |
171 // Smi or a heap number. | 171 // Smi or a heap number. |
172 if (NUMBER_IS_NAN(n) || n < r || | 172 if (NUMBER_IS_NAN(n) || n < r || |
173 (r == 0 && n == 0 && !%_IsSmi(n) && 1 / n < 0)) { | 173 (r == 0 && n == 0 && !%_IsSmi(n) && 1 / n < 0)) { |
174 r = n; | 174 r = n; |
175 } | 175 } |
176 } | 176 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 "tan", MathTan, | 289 "tan", MathTan, |
290 "atan2", MathAtan2, | 290 "atan2", MathAtan2, |
291 "pow", MathPow, | 291 "pow", MathPow, |
292 "max", MathMax, | 292 "max", MathMax, |
293 "min", MathMin, | 293 "min", MathMin, |
294 "imul", MathImul | 294 "imul", MathImul |
295 )); | 295 )); |
296 } | 296 } |
297 | 297 |
298 SetUpMath(); | 298 SetUpMath(); |
OLD | NEW |