| 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 25 matching lines...) Expand all Loading... |
| 36 y = +y; | 36 y = +y; |
| 37 x = +x; | 37 x = +x; |
| 38 return %MathAtan2(y, x); | 38 return %MathAtan2(y, x); |
| 39 } | 39 } |
| 40 | 40 |
| 41 // ECMA 262 - 15.8.2.8 | 41 // ECMA 262 - 15.8.2.8 |
| 42 function MathExp(x) { | 42 function MathExp(x) { |
| 43 return %MathExpRT(TO_NUMBER(x)); | 43 return %MathExpRT(TO_NUMBER(x)); |
| 44 } | 44 } |
| 45 | 45 |
| 46 // ECMA 262 - 15.8.2.10 | |
| 47 function MathLog(x) { | |
| 48 return %_MathLogRT(TO_NUMBER(x)); | |
| 49 } | |
| 50 | |
| 51 // ECMA 262 - 15.8.2.13 | 46 // ECMA 262 - 15.8.2.13 |
| 52 function MathPowJS(x, y) { | 47 function MathPowJS(x, y) { |
| 53 return %_MathPow(TO_NUMBER(x), TO_NUMBER(y)); | 48 return %_MathPow(TO_NUMBER(x), TO_NUMBER(y)); |
| 54 } | 49 } |
| 55 | 50 |
| 56 // ECMA 262 - 15.8.2.14 | 51 // ECMA 262 - 15.8.2.14 |
| 57 function MathRandom() { | 52 function MathRandom() { |
| 58 // While creating a startup snapshot, %GenerateRandomNumbers returns a | 53 // While creating a startup snapshot, %GenerateRandomNumbers returns a |
| 59 // normal array containing a single random number, and has to be called for | 54 // normal array containing a single random number, and has to be called for |
| 60 // every new random number. | 55 // every new random number. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 86 if (x < 0) return -1; | 81 if (x < 0) return -1; |
| 87 // -0, 0 or NaN. | 82 // -0, 0 or NaN. |
| 88 return x; | 83 return x; |
| 89 } | 84 } |
| 90 | 85 |
| 91 // ES6 draft 09-27-13, section 20.2.2.5. | 86 // ES6 draft 09-27-13, section 20.2.2.5. |
| 92 function MathAsinh(x) { | 87 function MathAsinh(x) { |
| 93 x = TO_NUMBER(x); | 88 x = TO_NUMBER(x); |
| 94 // Idempotent for NaN, +/-0 and +/-Infinity. | 89 // Idempotent for NaN, +/-0 and +/-Infinity. |
| 95 if (x === 0 || !NUMBER_IS_FINITE(x)) return x; | 90 if (x === 0 || !NUMBER_IS_FINITE(x)) return x; |
| 96 if (x > 0) return MathLog(x + %math_sqrt(x * x + 1)); | 91 if (x > 0) return %math_log(x + %math_sqrt(x * x + 1)); |
| 97 // This is to prevent numerical errors caused by large negative x. | 92 // This is to prevent numerical errors caused by large negative x. |
| 98 return -MathLog(-x + %math_sqrt(x * x + 1)); | 93 return -%math_log(-x + %math_sqrt(x * x + 1)); |
| 99 } | 94 } |
| 100 | 95 |
| 101 // ES6 draft 09-27-13, section 20.2.2.3. | 96 // ES6 draft 09-27-13, section 20.2.2.3. |
| 102 function MathAcosh(x) { | 97 function MathAcosh(x) { |
| 103 x = TO_NUMBER(x); | 98 x = TO_NUMBER(x); |
| 104 if (x < 1) return NaN; | 99 if (x < 1) return NaN; |
| 105 // Idempotent for NaN and +Infinity. | 100 // Idempotent for NaN and +Infinity. |
| 106 if (!NUMBER_IS_FINITE(x)) return x; | 101 if (!NUMBER_IS_FINITE(x)) return x; |
| 107 return MathLog(x + %math_sqrt(x + 1) * %math_sqrt(x - 1)); | 102 return %math_log(x + %math_sqrt(x + 1) * %math_sqrt(x - 1)); |
| 108 } | 103 } |
| 109 | 104 |
| 110 // ES6 draft 09-27-13, section 20.2.2.7. | 105 // ES6 draft 09-27-13, section 20.2.2.7. |
| 111 function MathAtanh(x) { | 106 function MathAtanh(x) { |
| 112 x = TO_NUMBER(x); | 107 x = TO_NUMBER(x); |
| 113 // Idempotent for +/-0. | 108 // Idempotent for +/-0. |
| 114 if (x === 0) return x; | 109 if (x === 0) return x; |
| 115 // Returns NaN for NaN and +/- Infinity. | 110 // Returns NaN for NaN and +/- Infinity. |
| 116 if (!NUMBER_IS_FINITE(x)) return NaN; | 111 if (!NUMBER_IS_FINITE(x)) return NaN; |
| 117 return 0.5 * MathLog((1 + x) / (1 - x)); | 112 return 0.5 * %math_log((1 + x) / (1 - x)); |
| 118 } | 113 } |
| 119 | 114 |
| 120 // ES6 draft 09-27-13, section 20.2.2.17. | 115 // ES6 draft 09-27-13, section 20.2.2.17. |
| 121 function MathHypot(x, y) { // Function length is 2. | 116 function MathHypot(x, y) { // Function length is 2. |
| 122 // We may want to introduce fast paths for two arguments and when | 117 // We may want to introduce fast paths for two arguments and when |
| 123 // normalization to avoid overflow is not necessary. For now, we | 118 // normalization to avoid overflow is not necessary. For now, we |
| 124 // simply assume the general case. | 119 // simply assume the general case. |
| 125 var length = arguments.length; | 120 var length = arguments.length; |
| 126 var max = 0; | 121 var max = 0; |
| 127 for (var i = 0; i < length; i++) { | 122 for (var i = 0; i < length; i++) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 "SQRT1_2", 0.7071067811865476, | 187 "SQRT1_2", 0.7071067811865476, |
| 193 "SQRT2", 1.4142135623730951 | 188 "SQRT2", 1.4142135623730951 |
| 194 ]); | 189 ]); |
| 195 | 190 |
| 196 // Set up non-enumerable functions of the Math object and | 191 // Set up non-enumerable functions of the Math object and |
| 197 // set their names. | 192 // set their names. |
| 198 utils.InstallFunctions(GlobalMath, DONT_ENUM, [ | 193 utils.InstallFunctions(GlobalMath, DONT_ENUM, [ |
| 199 "random", MathRandom, | 194 "random", MathRandom, |
| 200 "abs", MathAbs, | 195 "abs", MathAbs, |
| 201 "exp", MathExp, | 196 "exp", MathExp, |
| 202 "log", MathLog, | |
| 203 "atan2", MathAtan2JS, | 197 "atan2", MathAtan2JS, |
| 204 "pow", MathPowJS, | 198 "pow", MathPowJS, |
| 205 "sign", MathSign, | 199 "sign", MathSign, |
| 206 "asinh", MathAsinh, | 200 "asinh", MathAsinh, |
| 207 "acosh", MathAcosh, | 201 "acosh", MathAcosh, |
| 208 "atanh", MathAtanh, | 202 "atanh", MathAtanh, |
| 209 "hypot", MathHypot, | 203 "hypot", MathHypot, |
| 210 "cbrt", MathCbrt | 204 "cbrt", MathCbrt |
| 211 ]); | 205 ]); |
| 212 | 206 |
| 213 %SetForceInlineFlag(MathAbs); | 207 %SetForceInlineFlag(MathAbs); |
| 214 %SetForceInlineFlag(MathAtan2JS); | 208 %SetForceInlineFlag(MathAtan2JS); |
| 215 %SetForceInlineFlag(MathRandom); | 209 %SetForceInlineFlag(MathRandom); |
| 216 %SetForceInlineFlag(MathSign); | 210 %SetForceInlineFlag(MathSign); |
| 217 | 211 |
| 218 // ------------------------------------------------------------------- | 212 // ------------------------------------------------------------------- |
| 219 // Exports | 213 // Exports |
| 220 | 214 |
| 221 utils.Export(function(to) { | 215 utils.Export(function(to) { |
| 222 to.MathAbs = MathAbs; | 216 to.MathAbs = MathAbs; |
| 223 to.MathExp = MathExp; | 217 to.MathExp = MathExp; |
| 224 to.IntRandom = MathRandomRaw; | 218 to.IntRandom = MathRandomRaw; |
| 225 }); | 219 }); |
| 226 | 220 |
| 227 }) | 221 }) |
| OLD | NEW |