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 var rngstate; // Initialized to a Uint32Array during genesis. | 5 var rngstate; // Initialized to a Uint32Array during genesis. |
6 | 6 |
7 var $abs; | 7 var $abs; |
8 var $exp; | 8 var $exp; |
9 var $floor; | 9 var $floor; |
10 var $max; | 10 var $max; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 245 } |
246 return %_MathSqrt(sum) * max; | 246 return %_MathSqrt(sum) * max; |
247 } | 247 } |
248 | 248 |
249 // ES6 draft 09-27-13, section 20.2.2.16. | 249 // ES6 draft 09-27-13, section 20.2.2.16. |
250 function MathFroundJS(x) { | 250 function MathFroundJS(x) { |
251 return %MathFround(TO_NUMBER_INLINE(x)); | 251 return %MathFround(TO_NUMBER_INLINE(x)); |
252 } | 252 } |
253 | 253 |
254 // ES6 draft 07-18-14, section 20.2.2.11 | 254 // ES6 draft 07-18-14, section 20.2.2.11 |
255 function MathClz32(x) { | 255 function MathClz32JS(x) { |
256 x = ToUint32(TO_NUMBER_INLINE(x)); | 256 return %_MathClz32(x >>> 0); |
257 if (x == 0) return 32; | |
258 var result = 0; | |
259 // Binary search. | |
260 if ((x & 0xFFFF0000) === 0) { x <<= 16; result += 16; }; | |
261 if ((x & 0xFF000000) === 0) { x <<= 8; result += 8; }; | |
262 if ((x & 0xF0000000) === 0) { x <<= 4; result += 4; }; | |
263 if ((x & 0xC0000000) === 0) { x <<= 2; result += 2; }; | |
264 if ((x & 0x80000000) === 0) { x <<= 1; result += 1; }; | |
265 return result; | |
266 } | 257 } |
267 | 258 |
268 // ES6 draft 09-27-13, section 20.2.2.9. | 259 // ES6 draft 09-27-13, section 20.2.2.9. |
269 // Cube root approximation, refer to: http://metamerist.com/cbrt/cbrt.htm | 260 // Cube root approximation, refer to: http://metamerist.com/cbrt/cbrt.htm |
270 // Using initial approximation adapted from Kahan's cbrt and 4 iterations | 261 // Using initial approximation adapted from Kahan's cbrt and 4 iterations |
271 // of Newton's method. | 262 // of Newton's method. |
272 function MathCbrt(x) { | 263 function MathCbrt(x) { |
273 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); | 264 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
274 if (x == 0 || !NUMBER_IS_FINITE(x)) return x; | 265 if (x == 0 || !NUMBER_IS_FINITE(x)) return x; |
275 return x >= 0 ? CubeRoot(x) : -CubeRoot(-x); | 266 return x >= 0 ? CubeRoot(x) : -CubeRoot(-x); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 "min", MathMin, | 329 "min", MathMin, |
339 "imul", MathImul, | 330 "imul", MathImul, |
340 "sign", MathSign, | 331 "sign", MathSign, |
341 "trunc", MathTrunc, | 332 "trunc", MathTrunc, |
342 "tanh", MathTanh, | 333 "tanh", MathTanh, |
343 "asinh", MathAsinh, | 334 "asinh", MathAsinh, |
344 "acosh", MathAcosh, | 335 "acosh", MathAcosh, |
345 "atanh", MathAtanh, | 336 "atanh", MathAtanh, |
346 "hypot", MathHypot, | 337 "hypot", MathHypot, |
347 "fround", MathFroundJS, | 338 "fround", MathFroundJS, |
348 "clz32", MathClz32, | 339 "clz32", MathClz32JS, |
349 "cbrt", MathCbrt | 340 "cbrt", MathCbrt |
350 )); | 341 )); |
351 | 342 |
352 %SetInlineBuiltinFlag(MathAbs); | 343 %SetInlineBuiltinFlag(MathAbs); |
353 %SetInlineBuiltinFlag(MathCeil); | 344 %SetInlineBuiltinFlag(MathCeil); |
| 345 %SetInlineBuiltinFlag(MathClz32JS); |
354 %SetInlineBuiltinFlag(MathFloorJS); | 346 %SetInlineBuiltinFlag(MathFloorJS); |
355 %SetInlineBuiltinFlag(MathRandom); | 347 %SetInlineBuiltinFlag(MathRandom); |
356 %SetInlineBuiltinFlag(MathSqrtJS); | 348 %SetInlineBuiltinFlag(MathSqrtJS); |
357 | 349 |
358 // Expose to the global scope. | 350 // Expose to the global scope. |
359 $abs = MathAbs; | 351 $abs = MathAbs; |
360 $exp = MathExp; | 352 $exp = MathExp; |
361 $floor = MathFloorJS; | 353 $floor = MathFloorJS; |
362 $max = MathMax; | 354 $max = MathMax; |
363 $min = MathMin; | 355 $min = MathMin; |
364 | 356 |
365 })(); | 357 })(); |
OLD | NEW |