| 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 if (x == 0 || !NUMBER_IS_FINITE(x)) return x; | 275 if (x == 0 || !NUMBER_IS_FINITE(x)) return x; |
| 276 return x >= 0 ? CubeRoot(x) : -CubeRoot(-x); | 276 return x >= 0 ? CubeRoot(x) : -CubeRoot(-x); |
| 277 } | 277 } |
| 278 | 278 |
| 279 macro NEWTON_ITERATION_CBRT(x, approx) | 279 macro NEWTON_ITERATION_CBRT(x, approx) |
| 280 (1.0 / 3.0) * (x / (approx * approx) + 2 * approx); | 280 (1.0 / 3.0) * (x / (approx * approx) + 2 * approx); |
| 281 endmacro | 281 endmacro |
| 282 | 282 |
| 283 function CubeRoot(x) { | 283 function CubeRoot(x) { |
| 284 var approx_hi = MathFloorJS(%_DoubleHi(x) / 3) + 0x2A9F7893; | 284 var approx_hi = MathFloorJS(%_DoubleHi(x) / 3) + 0x2A9F7893; |
| 285 var approx = %_ConstructDouble(approx_hi, 0); | 285 var approx = %_ConstructDouble(approx_hi | 0, 0); |
| 286 approx = NEWTON_ITERATION_CBRT(x, approx); | 286 approx = NEWTON_ITERATION_CBRT(x, approx); |
| 287 approx = NEWTON_ITERATION_CBRT(x, approx); | 287 approx = NEWTON_ITERATION_CBRT(x, approx); |
| 288 approx = NEWTON_ITERATION_CBRT(x, approx); | 288 approx = NEWTON_ITERATION_CBRT(x, approx); |
| 289 return NEWTON_ITERATION_CBRT(x, approx); | 289 return NEWTON_ITERATION_CBRT(x, approx); |
| 290 } | 290 } |
| 291 | 291 |
| 292 // ------------------------------------------------------------------- | 292 // ------------------------------------------------------------------- |
| 293 | 293 |
| 294 %AddNamedProperty(GlobalMath, toStringTagSymbol, "Math", READ_ONLY | DONT_ENUM); | 294 %AddNamedProperty(GlobalMath, toStringTagSymbol, "Math", READ_ONLY | DONT_ENUM); |
| 295 | 295 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 utils.Export(function(to) { | 358 utils.Export(function(to) { |
| 359 to.MathAbs = MathAbs; | 359 to.MathAbs = MathAbs; |
| 360 to.MathExp = MathExp; | 360 to.MathExp = MathExp; |
| 361 to.MathFloor = MathFloorJS; | 361 to.MathFloor = MathFloorJS; |
| 362 to.IntRandom = MathRandomRaw; | 362 to.IntRandom = MathRandomRaw; |
| 363 to.MathMax = MathMax; | 363 to.MathMax = MathMax; |
| 364 to.MathMin = MathMin; | 364 to.MathMin = MathMin; |
| 365 }); | 365 }); |
| 366 | 366 |
| 367 }) | 367 }) |
| OLD | NEW |