| 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; |
| 11 var $min; | 11 var $min; |
| 12 | 12 |
| 13 (function() { | 13 (function() { |
| 14 | 14 |
| 15 "use strict"; | 15 "use strict"; |
| 16 | 16 |
| 17 %CheckIsBootstrapping(); | 17 %CheckIsBootstrapping(); |
| 18 | 18 |
| 19 var GlobalObject = global.Object; | 19 var GlobalObject = global.Object; |
| 20 var GlobalArray = global.Array; | 20 var GlobalArray = global.Array; |
| 21 | 21 |
| 22 //------------------------------------------------------------------- | 22 //------------------------------------------------------------------- |
| 23 | 23 |
| 24 // ECMA 262 - 15.8.2.1 | 24 // ECMA 262 - 15.8.2.1 |
| 25 function MathAbs(x) { | 25 function MathAbs(x) { |
| 26 if (%_IsSmi(x)) return x >= 0 ? x : -x; | 26 x = +x; |
| 27 x = TO_NUMBER_INLINE(x); | 27 if (x > 0) return x; |
| 28 if (x === 0) return 0; // To handle -0. | 28 return 0 - x; |
| 29 return x > 0 ? x : -x; | |
| 30 } | 29 } |
| 31 | 30 |
| 32 // ECMA 262 - 15.8.2.2 | 31 // ECMA 262 - 15.8.2.2 |
| 33 function MathAcosJS(x) { | 32 function MathAcosJS(x) { |
| 34 return %MathAcos(TO_NUMBER_INLINE(x)); | 33 return %MathAcos(TO_NUMBER_INLINE(x)); |
| 35 } | 34 } |
| 36 | 35 |
| 37 // ECMA 262 - 15.8.2.3 | 36 // ECMA 262 - 15.8.2.3 |
| 38 function MathAsinJS(x) { | 37 function MathAsinJS(x) { |
| 39 return %MathAsin(TO_NUMBER_INLINE(x)); | 38 return %MathAsin(TO_NUMBER_INLINE(x)); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 return (x < 0 ? (x + 0x100000000) : x) * 2.3283064365386962890625e-10; | 140 return (x < 0 ? (x + 0x100000000) : x) * 2.3283064365386962890625e-10; |
| 142 } | 141 } |
| 143 | 142 |
| 144 // ECMA 262 - 15.8.2.15 | 143 // ECMA 262 - 15.8.2.15 |
| 145 function MathRound(x) { | 144 function MathRound(x) { |
| 146 return %RoundNumber(TO_NUMBER_INLINE(x)); | 145 return %RoundNumber(TO_NUMBER_INLINE(x)); |
| 147 } | 146 } |
| 148 | 147 |
| 149 // ECMA 262 - 15.8.2.17 | 148 // ECMA 262 - 15.8.2.17 |
| 150 function MathSqrt(x) { | 149 function MathSqrt(x) { |
| 151 return %_MathSqrtRT(TO_NUMBER_INLINE(x)); | 150 return %_MathSqrt(+x); |
| 152 } | 151 } |
| 153 | 152 |
| 154 // Non-standard extension. | 153 // Non-standard extension. |
| 155 function MathImul(x, y) { | 154 function MathImul(x, y) { |
| 156 return %NumberImul(TO_NUMBER_INLINE(x), TO_NUMBER_INLINE(y)); | 155 return %NumberImul(TO_NUMBER_INLINE(x), TO_NUMBER_INLINE(y)); |
| 157 } | 156 } |
| 158 | 157 |
| 159 // ES6 draft 09-27-13, section 20.2.2.28. | 158 // ES6 draft 09-27-13, section 20.2.2.28. |
| 160 function MathSign(x) { | 159 function MathSign(x) { |
| 161 x = TO_NUMBER_INLINE(x); | 160 x = TO_NUMBER_INLINE(x); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 184 var exp1 = MathExp(x); | 183 var exp1 = MathExp(x); |
| 185 var exp2 = MathExp(-x); | 184 var exp2 = MathExp(-x); |
| 186 return (exp1 - exp2) / (exp1 + exp2); | 185 return (exp1 - exp2) / (exp1 + exp2); |
| 187 } | 186 } |
| 188 | 187 |
| 189 // ES6 draft 09-27-13, section 20.2.2.5. | 188 // ES6 draft 09-27-13, section 20.2.2.5. |
| 190 function MathAsinh(x) { | 189 function MathAsinh(x) { |
| 191 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); | 190 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
| 192 // Idempotent for NaN, +/-0 and +/-Infinity. | 191 // Idempotent for NaN, +/-0 and +/-Infinity. |
| 193 if (x === 0 || !NUMBER_IS_FINITE(x)) return x; | 192 if (x === 0 || !NUMBER_IS_FINITE(x)) return x; |
| 194 if (x > 0) return MathLog(x + MathSqrt(x * x + 1)); | 193 if (x > 0) return MathLog(x + %_MathSqrt(x * x + 1)); |
| 195 // This is to prevent numerical errors caused by large negative x. | 194 // This is to prevent numerical errors caused by large negative x. |
| 196 return -MathLog(-x + MathSqrt(x * x + 1)); | 195 return -MathLog(-x + %_MathSqrt(x * x + 1)); |
| 197 } | 196 } |
| 198 | 197 |
| 199 // ES6 draft 09-27-13, section 20.2.2.3. | 198 // ES6 draft 09-27-13, section 20.2.2.3. |
| 200 function MathAcosh(x) { | 199 function MathAcosh(x) { |
| 201 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); | 200 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
| 202 if (x < 1) return NAN; | 201 if (x < 1) return NAN; |
| 203 // Idempotent for NaN and +Infinity. | 202 // Idempotent for NaN and +Infinity. |
| 204 if (!NUMBER_IS_FINITE(x)) return x; | 203 if (!NUMBER_IS_FINITE(x)) return x; |
| 205 return MathLog(x + MathSqrt(x + 1) * MathSqrt(x - 1)); | 204 return MathLog(x + %_MathSqrt(x + 1) * %_MathSqrt(x - 1)); |
| 206 } | 205 } |
| 207 | 206 |
| 208 // ES6 draft 09-27-13, section 20.2.2.7. | 207 // ES6 draft 09-27-13, section 20.2.2.7. |
| 209 function MathAtanh(x) { | 208 function MathAtanh(x) { |
| 210 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); | 209 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
| 211 // Idempotent for +/-0. | 210 // Idempotent for +/-0. |
| 212 if (x === 0) return x; | 211 if (x === 0) return x; |
| 213 // Returns NaN for NaN and +/- Infinity. | 212 // Returns NaN for NaN and +/- Infinity. |
| 214 if (!NUMBER_IS_FINITE(x)) return NAN; | 213 if (!NUMBER_IS_FINITE(x)) return NAN; |
| 215 return 0.5 * MathLog((1 + x) / (1 - x)); | 214 return 0.5 * MathLog((1 + x) / (1 - x)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 237 if (max === 0) max = 1; | 236 if (max === 0) max = 1; |
| 238 var sum = 0; | 237 var sum = 0; |
| 239 var compensation = 0; | 238 var compensation = 0; |
| 240 for (var i = 0; i < length; i++) { | 239 for (var i = 0; i < length; i++) { |
| 241 var n = args[i] / max; | 240 var n = args[i] / max; |
| 242 var summand = n * n - compensation; | 241 var summand = n * n - compensation; |
| 243 var preliminary = sum + summand; | 242 var preliminary = sum + summand; |
| 244 compensation = (preliminary - sum) - summand; | 243 compensation = (preliminary - sum) - summand; |
| 245 sum = preliminary; | 244 sum = preliminary; |
| 246 } | 245 } |
| 247 return MathSqrt(sum) * max; | 246 return %_MathSqrt(sum) * max; |
| 248 } | 247 } |
| 249 | 248 |
| 250 // ES6 draft 09-27-13, section 20.2.2.16. | 249 // ES6 draft 09-27-13, section 20.2.2.16. |
| 251 function MathFroundJS(x) { | 250 function MathFroundJS(x) { |
| 252 return %MathFround(TO_NUMBER_INLINE(x)); | 251 return %MathFround(TO_NUMBER_INLINE(x)); |
| 253 } | 252 } |
| 254 | 253 |
| 255 // ES6 draft 07-18-14, section 20.2.2.11 | 254 // ES6 draft 07-18-14, section 20.2.2.11 |
| 256 function MathClz32(x) { | 255 function MathClz32(x) { |
| 257 x = ToUint32(TO_NUMBER_INLINE(x)); | 256 x = ToUint32(TO_NUMBER_INLINE(x)); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 "tanh", MathTanh, | 342 "tanh", MathTanh, |
| 344 "asinh", MathAsinh, | 343 "asinh", MathAsinh, |
| 345 "acosh", MathAcosh, | 344 "acosh", MathAcosh, |
| 346 "atanh", MathAtanh, | 345 "atanh", MathAtanh, |
| 347 "hypot", MathHypot, | 346 "hypot", MathHypot, |
| 348 "fround", MathFroundJS, | 347 "fround", MathFroundJS, |
| 349 "clz32", MathClz32, | 348 "clz32", MathClz32, |
| 350 "cbrt", MathCbrt | 349 "cbrt", MathCbrt |
| 351 )); | 350 )); |
| 352 | 351 |
| 352 %SetInlineBuiltinFlag(MathAbs); |
| 353 %SetInlineBuiltinFlag(MathCeil); | 353 %SetInlineBuiltinFlag(MathCeil); |
| 354 %SetInlineBuiltinFlag(MathFloor); | 354 %SetInlineBuiltinFlag(MathFloor); |
| 355 %SetInlineBuiltinFlag(MathRandom); | 355 %SetInlineBuiltinFlag(MathRandom); |
| 356 %SetInlineBuiltinFlag(MathSqrt); |
| 356 | 357 |
| 357 // Expose to the global scope. | 358 // Expose to the global scope. |
| 358 $abs = MathAbs; | 359 $abs = MathAbs; |
| 359 $exp = MathExp; | 360 $exp = MathExp; |
| 360 $floor = MathFloor; | 361 $floor = MathFloor; |
| 361 $max = MathMax; | 362 $max = MathMax; |
| 362 $min = MathMin; | 363 $min = MathMin; |
| 363 | 364 |
| 364 })(); | 365 })(); |
| OLD | NEW |