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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 // ECMA 262 - 15.8.2.5 | 51 // ECMA 262 - 15.8.2.5 |
52 // The naming of y and x matches the spec, as does the order in which | 52 // The naming of y and x matches the spec, as does the order in which |
53 // ToNumber (valueOf) is called. | 53 // ToNumber (valueOf) is called. |
54 function MathAtan2JS(y, x) { | 54 function MathAtan2JS(y, x) { |
55 return %MathAtan2(TO_NUMBER_INLINE(y), TO_NUMBER_INLINE(x)); | 55 return %MathAtan2(TO_NUMBER_INLINE(y), TO_NUMBER_INLINE(x)); |
56 } | 56 } |
57 | 57 |
58 // ECMA 262 - 15.8.2.6 | 58 // ECMA 262 - 15.8.2.6 |
59 function MathCeil(x) { | 59 function MathCeil(x) { |
60 return -MathFloor(-x); | 60 return -%_MathFloor(-x); |
61 } | 61 } |
62 | 62 |
63 // ECMA 262 - 15.8.2.8 | 63 // ECMA 262 - 15.8.2.8 |
64 function MathExp(x) { | 64 function MathExp(x) { |
65 return %MathExpRT(TO_NUMBER_INLINE(x)); | 65 return %MathExpRT(TO_NUMBER_INLINE(x)); |
66 } | 66 } |
67 | 67 |
68 // ECMA 262 - 15.8.2.9 | 68 // ECMA 262 - 15.8.2.9 |
69 function MathFloor(x) { | 69 function MathFloor(x) { |
70 x = TO_NUMBER_INLINE(x); | 70 return %_MathFloor(+x); |
71 // It's more common to call this with a positive number that's out | |
72 // of range than negative numbers; check the upper bound first. | |
73 if (x < 0x80000000 && x > 0) { | |
74 // Numbers in the range [0, 2^31) can be floored by converting | |
75 // them to an unsigned 32-bit value using the shift operator. | |
76 // We avoid doing so for -0, because the result of Math.floor(-0) | |
77 // has to be -0, which wouldn't be the case with the shift. | |
78 return TO_UINT32(x); | |
79 } else { | |
80 return %MathFloorRT(x); | |
81 } | |
82 } | 71 } |
83 | 72 |
84 // ECMA 262 - 15.8.2.10 | 73 // ECMA 262 - 15.8.2.10 |
85 function MathLog(x) { | 74 function MathLog(x) { |
86 return %_MathLogRT(TO_NUMBER_INLINE(x)); | 75 return %_MathLogRT(TO_NUMBER_INLINE(x)); |
87 } | 76 } |
88 | 77 |
89 // ECMA 262 - 15.8.2.11 | 78 // ECMA 262 - 15.8.2.11 |
90 function MathMax(arg1, arg2) { // length == 2 | 79 function MathMax(arg1, arg2) { // length == 2 |
91 var length = %_ArgumentsLength(); | 80 var length = %_ArgumentsLength(); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // Keep reference to original values of some global properties. This | 356 // Keep reference to original values of some global properties. This |
368 // has the added benefit that the code in this file is isolated from | 357 // has the added benefit that the code in this file is isolated from |
369 // changes to these properties. | 358 // changes to these properties. |
370 $abs = MathAbs; | 359 $abs = MathAbs; |
371 $exp = MathExp; | 360 $exp = MathExp; |
372 $floor = MathFloor; | 361 $floor = MathFloor; |
373 $max = MathMax; | 362 $max = MathMax; |
374 $min = MathMin; | 363 $min = MathMin; |
375 | 364 |
376 })(); | 365 })(); |
OLD | NEW |