OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 "use strict"; | 5 "use strict"; |
6 | 6 |
7 // This file relies on the fact that the following declarations have been made | 7 // This file relies on the fact that the following declarations have been made |
8 // in runtime.js: | 8 // in runtime.js: |
9 // var $Object = global.Object; | 9 // var $Object = global.Object; |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 } | 40 } |
41 | 41 |
42 // ECMA 262 - 15.8.2.4 | 42 // ECMA 262 - 15.8.2.4 |
43 function MathAtan(x) { | 43 function MathAtan(x) { |
44 return %MathAtan(TO_NUMBER_INLINE(x)); | 44 return %MathAtan(TO_NUMBER_INLINE(x)); |
45 } | 45 } |
46 | 46 |
47 // ECMA 262 - 15.8.2.5 | 47 // ECMA 262 - 15.8.2.5 |
48 // The naming of y and x matches the spec, as does the order in which | 48 // The naming of y and x matches the spec, as does the order in which |
49 // ToNumber (valueOf) is called. | 49 // ToNumber (valueOf) is called. |
50 function MathAtan2(y, x) { | 50 function MathAtan2JS(y, x) { |
51 return %MathAtan2(TO_NUMBER_INLINE(y), TO_NUMBER_INLINE(x)); | 51 return %MathAtan2(TO_NUMBER_INLINE(y), TO_NUMBER_INLINE(x)); |
52 } | 52 } |
53 | 53 |
54 // ECMA 262 - 15.8.2.6 | 54 // ECMA 262 - 15.8.2.6 |
55 function MathCeil(x) { | 55 function MathCeil(x) { |
56 return -MathFloor(-x); | 56 return -MathFloor(-x); |
57 } | 57 } |
58 | 58 |
59 // ECMA 262 - 15.8.2.7 | 59 // ECMA 262 - 15.8.2.7 |
60 function MathCos(x) { | 60 function MathCos(x) { |
61 x = MathAbs(x); // Convert to number and get rid of -0. | 61 x = MathAbs(x); // Convert to number and get rid of -0. |
62 return TrigonometricInterpolation(x, 1); | 62 return TrigonometricInterpolation(x, 1); |
63 } | 63 } |
64 | 64 |
65 // ECMA 262 - 15.8.2.8 | 65 // ECMA 262 - 15.8.2.8 |
66 function MathExp(x) { | 66 function MathExp(x) { |
67 return %MathExp(TO_NUMBER_INLINE(x)); | 67 return %MathExpRT(TO_NUMBER_INLINE(x)); |
68 } | 68 } |
69 | 69 |
70 // ECMA 262 - 15.8.2.9 | 70 // ECMA 262 - 15.8.2.9 |
71 function MathFloor(x) { | 71 function MathFloor(x) { |
72 x = TO_NUMBER_INLINE(x); | 72 x = TO_NUMBER_INLINE(x); |
73 // It's more common to call this with a positive number that's out | 73 // It's more common to call this with a positive number that's out |
74 // of range than negative numbers; check the upper bound first. | 74 // of range than negative numbers; check the upper bound first. |
75 if (x < 0x80000000 && x > 0) { | 75 if (x < 0x80000000 && x > 0) { |
76 // Numbers in the range [0, 2^31) can be floored by converting | 76 // Numbers in the range [0, 2^31) can be floored by converting |
77 // them to an unsigned 32-bit value using the shift operator. | 77 // them to an unsigned 32-bit value using the shift operator. |
78 // We avoid doing so for -0, because the result of Math.floor(-0) | 78 // We avoid doing so for -0, because the result of Math.floor(-0) |
79 // has to be -0, which wouldn't be the case with the shift. | 79 // has to be -0, which wouldn't be the case with the shift. |
80 return TO_UINT32(x); | 80 return TO_UINT32(x); |
81 } else { | 81 } else { |
82 return %MathFloor(x); | 82 return %MathFloorRT(x); |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 // ECMA 262 - 15.8.2.10 | 86 // ECMA 262 - 15.8.2.10 |
87 function MathLog(x) { | 87 function MathLog(x) { |
88 return %_MathLog(TO_NUMBER_INLINE(x)); | 88 return %_MathLog(TO_NUMBER_INLINE(x)); |
89 } | 89 } |
90 | 90 |
91 // ECMA 262 - 15.8.2.11 | 91 // ECMA 262 - 15.8.2.11 |
92 function MathMax(arg1, arg2) { // length == 2 | 92 function MathMax(arg1, arg2) { // length == 2 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 166 |
167 // ECMA 262 - 15.8.2.16 | 167 // ECMA 262 - 15.8.2.16 |
168 function MathSin(x) { | 168 function MathSin(x) { |
169 x = x * 1; // Convert to number and deal with -0. | 169 x = x * 1; // Convert to number and deal with -0. |
170 if (%_IsMinusZero(x)) return x; | 170 if (%_IsMinusZero(x)) return x; |
171 return TrigonometricInterpolation(x, 0); | 171 return TrigonometricInterpolation(x, 0); |
172 } | 172 } |
173 | 173 |
174 // ECMA 262 - 15.8.2.17 | 174 // ECMA 262 - 15.8.2.17 |
175 function MathSqrt(x) { | 175 function MathSqrt(x) { |
176 return %_MathSqrt(TO_NUMBER_INLINE(x)); | 176 return %_MathSqrtRT(TO_NUMBER_INLINE(x)); |
177 } | 177 } |
178 | 178 |
179 // ECMA 262 - 15.8.2.18 | 179 // ECMA 262 - 15.8.2.18 |
180 function MathTan(x) { | 180 function MathTan(x) { |
181 return MathSin(x) / MathCos(x); | 181 return MathSin(x) / MathCos(x); |
182 } | 182 } |
183 | 183 |
184 // Non-standard extension. | 184 // Non-standard extension. |
185 function MathImul(x, y) { | 185 function MathImul(x, y) { |
186 return %NumberImul(TO_NUMBER_INLINE(x), TO_NUMBER_INLINE(y)); | 186 return %NumberImul(TO_NUMBER_INLINE(x), TO_NUMBER_INLINE(y)); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 "atan", MathAtan, | 289 "atan", MathAtan, |
290 "ceil", MathCeil, | 290 "ceil", MathCeil, |
291 "cos", MathCos, | 291 "cos", MathCos, |
292 "exp", MathExp, | 292 "exp", MathExp, |
293 "floor", MathFloor, | 293 "floor", MathFloor, |
294 "log", MathLog, | 294 "log", MathLog, |
295 "round", MathRound, | 295 "round", MathRound, |
296 "sin", MathSin, | 296 "sin", MathSin, |
297 "sqrt", MathSqrt, | 297 "sqrt", MathSqrt, |
298 "tan", MathTan, | 298 "tan", MathTan, |
299 "atan2", MathAtan2, | 299 "atan2", MathAtan2JS, |
300 "pow", MathPow, | 300 "pow", MathPow, |
301 "max", MathMax, | 301 "max", MathMax, |
302 "min", MathMin, | 302 "min", MathMin, |
303 "imul", MathImul | 303 "imul", MathImul |
304 )); | 304 )); |
305 | 305 |
306 %SetInlineBuiltinFlag(MathCeil); | 306 %SetInlineBuiltinFlag(MathCeil); |
307 %SetInlineBuiltinFlag(MathRandom); | 307 %SetInlineBuiltinFlag(MathRandom); |
308 %SetInlineBuiltinFlag(MathSin); | 308 %SetInlineBuiltinFlag(MathSin); |
309 %SetInlineBuiltinFlag(MathCos); | 309 %SetInlineBuiltinFlag(MathCos); |
310 %SetInlineBuiltinFlag(MathTan); | 310 %SetInlineBuiltinFlag(MathTan); |
311 %SetInlineBuiltinFlag(TrigonometricInterpolation); | 311 %SetInlineBuiltinFlag(TrigonometricInterpolation); |
312 } | 312 } |
313 | 313 |
314 SetUpMath(); | 314 SetUpMath(); |
OLD | NEW |