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 (function(global, utils) { | 5 (function(global, utils) { |
6 "use strict"; | 6 "use strict"; |
7 | 7 |
8 %CheckIsBootstrapping(); | 8 %CheckIsBootstrapping(); |
9 | 9 |
10 // ------------------------------------------------------------------- | 10 // ------------------------------------------------------------------- |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // ECMA 262 - 15.8.2.9 | 68 // ECMA 262 - 15.8.2.9 |
69 function MathFloorJS(x) { | 69 function MathFloorJS(x) { |
70 return %_MathFloor(+x); | 70 return %_MathFloor(+x); |
71 } | 71 } |
72 | 72 |
73 // ECMA 262 - 15.8.2.10 | 73 // ECMA 262 - 15.8.2.10 |
74 function MathLog(x) { | 74 function MathLog(x) { |
75 return %_MathLogRT(TO_NUMBER(x)); | 75 return %_MathLogRT(TO_NUMBER(x)); |
76 } | 76 } |
77 | 77 |
78 // ECMA 262 - 15.8.2.11 | |
79 function MathMax(arg1, arg2) { // length == 2 | |
80 var length = %_ArgumentsLength(); | |
81 if (length == 2) { | |
82 arg1 = TO_NUMBER(arg1); | |
83 arg2 = TO_NUMBER(arg2); | |
84 if (arg2 > arg1) return arg2; | |
85 if (arg1 > arg2) return arg1; | |
86 if (arg1 == arg2) { | |
87 // Make sure -0 is considered less than +0. | |
88 return (arg1 === 0 && %_IsMinusZero(arg1)) ? arg2 : arg1; | |
89 } | |
90 // All comparisons failed, one of the arguments must be NaN. | |
91 return NaN; | |
92 } | |
93 var r = -INFINITY; | |
94 for (var i = 0; i < length; i++) { | |
95 var n = %_Arguments(i); | |
96 n = TO_NUMBER(n); | |
97 // Make sure +0 is considered greater than -0. | |
98 if (NUMBER_IS_NAN(n) || n > r || (r === 0 && n === 0 && %_IsMinusZero(r))) { | |
99 r = n; | |
100 } | |
101 } | |
102 return r; | |
103 } | |
104 | |
105 // ECMA 262 - 15.8.2.12 | |
106 function MathMin(arg1, arg2) { // length == 2 | |
107 var length = %_ArgumentsLength(); | |
108 if (length == 2) { | |
109 arg1 = TO_NUMBER(arg1); | |
110 arg2 = TO_NUMBER(arg2); | |
111 if (arg2 > arg1) return arg1; | |
112 if (arg1 > arg2) return arg2; | |
113 if (arg1 == arg2) { | |
114 // Make sure -0 is considered less than +0. | |
115 return (arg1 === 0 && %_IsMinusZero(arg1)) ? arg1 : arg2; | |
116 } | |
117 // All comparisons failed, one of the arguments must be NaN. | |
118 return NaN; | |
119 } | |
120 var r = INFINITY; | |
121 for (var i = 0; i < length; i++) { | |
122 var n = %_Arguments(i); | |
123 n = TO_NUMBER(n); | |
124 // Make sure -0 is considered less than +0. | |
125 if (NUMBER_IS_NAN(n) || n < r || (r === 0 && n === 0 && %_IsMinusZero(n))) { | |
126 r = n; | |
127 } | |
128 } | |
129 return r; | |
130 } | |
131 | |
132 // ECMA 262 - 15.8.2.13 | 78 // ECMA 262 - 15.8.2.13 |
133 function MathPowJS(x, y) { | 79 function MathPowJS(x, y) { |
134 return %_MathPow(TO_NUMBER(x), TO_NUMBER(y)); | 80 return %_MathPow(TO_NUMBER(x), TO_NUMBER(y)); |
135 } | 81 } |
136 | 82 |
137 // ECMA 262 - 15.8.2.14 | 83 // ECMA 262 - 15.8.2.14 |
138 function MathRandom() { | 84 function MathRandom() { |
139 if (nextRandomIndex >= kRandomBatchSize) { | 85 if (nextRandomIndex >= kRandomBatchSize) { |
140 randomNumbers = %GenerateRandomNumbers(randomNumbers); | 86 randomNumbers = %GenerateRandomNumbers(randomNumbers); |
141 nextRandomIndex = kRandomNumberStart; | 87 nextRandomIndex = kRandomNumberStart; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 "asin", MathAsinJS, | 253 "asin", MathAsinJS, |
308 "atan", MathAtanJS, | 254 "atan", MathAtanJS, |
309 "ceil", MathCeil, | 255 "ceil", MathCeil, |
310 "exp", MathExp, | 256 "exp", MathExp, |
311 "floor", MathFloorJS, | 257 "floor", MathFloorJS, |
312 "log", MathLog, | 258 "log", MathLog, |
313 "round", MathRound, | 259 "round", MathRound, |
314 "sqrt", MathSqrtJS, | 260 "sqrt", MathSqrtJS, |
315 "atan2", MathAtan2JS, | 261 "atan2", MathAtan2JS, |
316 "pow", MathPowJS, | 262 "pow", MathPowJS, |
317 "max", MathMax, | |
318 "min", MathMin, | |
319 "imul", MathImul, | 263 "imul", MathImul, |
320 "sign", MathSign, | 264 "sign", MathSign, |
321 "trunc", MathTrunc, | 265 "trunc", MathTrunc, |
322 "asinh", MathAsinh, | 266 "asinh", MathAsinh, |
323 "acosh", MathAcosh, | 267 "acosh", MathAcosh, |
324 "atanh", MathAtanh, | 268 "atanh", MathAtanh, |
325 "hypot", MathHypot, | 269 "hypot", MathHypot, |
326 "fround", MathFroundJS, | 270 "fround", MathFroundJS, |
327 "clz32", MathClz32JS, | 271 "clz32", MathClz32JS, |
328 "cbrt", MathCbrt | 272 "cbrt", MathCbrt |
(...skipping 13 matching lines...) Expand all Loading... |
342 %SetForceInlineFlag(MathTrunc); | 286 %SetForceInlineFlag(MathTrunc); |
343 | 287 |
344 // ------------------------------------------------------------------- | 288 // ------------------------------------------------------------------- |
345 // Exports | 289 // Exports |
346 | 290 |
347 utils.Export(function(to) { | 291 utils.Export(function(to) { |
348 to.MathAbs = MathAbs; | 292 to.MathAbs = MathAbs; |
349 to.MathExp = MathExp; | 293 to.MathExp = MathExp; |
350 to.MathFloor = MathFloorJS; | 294 to.MathFloor = MathFloorJS; |
351 to.IntRandom = MathRandomRaw; | 295 to.IntRandom = MathRandomRaw; |
352 to.MathMax = MathMax; | |
353 to.MathMin = MathMin; | |
354 }); | 296 }); |
355 | 297 |
356 }) | 298 }) |
OLD | NEW |