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 12 matching lines...) Expand all Loading... |
23 | 23 |
24 // ECMA 262 - 15.8.2.1 | 24 // ECMA 262 - 15.8.2.1 |
25 function MathAbs(x) { | 25 function MathAbs(x) { |
26 if (%_IsSmi(x)) return x >= 0 ? x : -x; | 26 if (%_IsSmi(x)) return x >= 0 ? x : -x; |
27 x = TO_NUMBER_INLINE(x); | 27 x = TO_NUMBER_INLINE(x); |
28 if (x === 0) return 0; // To handle -0. | 28 if (x === 0) return 0; // To handle -0. |
29 return x > 0 ? x : -x; | 29 return x > 0 ? x : -x; |
30 } | 30 } |
31 | 31 |
32 // ECMA 262 - 15.8.2.2 | 32 // ECMA 262 - 15.8.2.2 |
33 function MathAcos(x) { | 33 function MathAcosJS(x) { |
34 return %MathAcos(TO_NUMBER_INLINE(x)); | 34 return %MathAcos(TO_NUMBER_INLINE(x)); |
35 } | 35 } |
36 | 36 |
37 // ECMA 262 - 15.8.2.3 | 37 // ECMA 262 - 15.8.2.3 |
38 function MathAsin(x) { | 38 function MathAsinJS(x) { |
39 return %MathAsin(TO_NUMBER_INLINE(x)); | 39 return %MathAsin(TO_NUMBER_INLINE(x)); |
40 } | 40 } |
41 | 41 |
42 // ECMA 262 - 15.8.2.4 | 42 // ECMA 262 - 15.8.2.4 |
43 function MathAtan(x) { | 43 function MathAtanJS(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 MathAtan2JS(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 |
(...skipping 24 matching lines...) Expand all Loading... |
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 %MathFloorRT(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 %_MathLogRT(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 |
93 var length = %_ArgumentsLength(); | 93 var length = %_ArgumentsLength(); |
94 if (length == 2) { | 94 if (length == 2) { |
95 arg1 = TO_NUMBER_INLINE(arg1); | 95 arg1 = TO_NUMBER_INLINE(arg1); |
96 arg2 = TO_NUMBER_INLINE(arg2); | 96 arg2 = TO_NUMBER_INLINE(arg2); |
97 if (arg2 > arg1) return arg2; | 97 if (arg2 > arg1) return arg2; |
98 if (arg1 > arg2) return arg1; | 98 if (arg1 > arg2) return arg1; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 "PI", 3.1415926535897932, | 277 "PI", 3.1415926535897932, |
278 "SQRT1_2", 0.7071067811865476, | 278 "SQRT1_2", 0.7071067811865476, |
279 "SQRT2", 1.4142135623730951 | 279 "SQRT2", 1.4142135623730951 |
280 )); | 280 )); |
281 | 281 |
282 // Set up non-enumerable functions of the Math object and | 282 // Set up non-enumerable functions of the Math object and |
283 // set their names. | 283 // set their names. |
284 InstallFunctions($Math, DONT_ENUM, $Array( | 284 InstallFunctions($Math, DONT_ENUM, $Array( |
285 "random", MathRandom, | 285 "random", MathRandom, |
286 "abs", MathAbs, | 286 "abs", MathAbs, |
287 "acos", MathAcos, | 287 "acos", MathAcosJS, |
288 "asin", MathAsin, | 288 "asin", MathAsinJS, |
289 "atan", MathAtan, | 289 "atan", MathAtanJS, |
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", MathAtan2JS, | 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 |