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 "use strict"; | 5 "use strict"; |
6 | 6 |
7 // This file relies on the fact that the following declarations have been made | 7 // This file relies on the fact that the following declarations have been made |
8 // in runtime.js: | 8 // in runtime.js: |
9 // var $Object = global.Object; | 9 // var $Object = global.Object; |
10 | 10 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 179 |
180 // ES6 draft 09-27-13, section 20.2.2.34. | 180 // ES6 draft 09-27-13, section 20.2.2.34. |
181 function MathTrunc(x) { | 181 function MathTrunc(x) { |
182 x = TO_NUMBER_INLINE(x); | 182 x = TO_NUMBER_INLINE(x); |
183 if (x > 0) return MathFloor(x); | 183 if (x > 0) return MathFloor(x); |
184 if (x < 0) return MathCeil(x); | 184 if (x < 0) return MathCeil(x); |
185 // -0, 0 or NaN. | 185 // -0, 0 or NaN. |
186 return x; | 186 return x; |
187 } | 187 } |
188 | 188 |
189 // ES6 draft 09-27-13, section 20.2.2.12. | |
190 function MathCosh(x) { | |
191 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); | |
192 if (!NUMBER_IS_FINITE(x)) return MathAbs(x); | |
193 return (MathExp(x) + MathExp(-x)) / 2; | |
194 } | |
195 | |
196 // ES6 draft 09-27-13, section 20.2.2.33. | 189 // ES6 draft 09-27-13, section 20.2.2.33. |
197 function MathTanh(x) { | 190 function MathTanh(x) { |
198 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); | 191 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); |
199 // Idempotent for +/-0. | 192 // Idempotent for +/-0. |
200 if (x === 0) return x; | 193 if (x === 0) return x; |
201 // Returns +/-1 for +/-Infinity. | 194 // Returns +/-1 for +/-Infinity. |
202 if (!NUMBER_IS_FINITE(x)) return MathSign(x); | 195 if (!NUMBER_IS_FINITE(x)) return MathSign(x); |
203 var exp1 = MathExp(x); | 196 var exp1 = MathExp(x); |
204 var exp2 = MathExp(-x); | 197 var exp2 = MathExp(-x); |
205 return (exp1 - exp2) / (exp1 + exp2); | 198 return (exp1 - exp2) / (exp1 + exp2); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 "sqrt", MathSqrt, | 355 "sqrt", MathSqrt, |
363 "tan", MathTan, // implemented by third_party/fdlibm | 356 "tan", MathTan, // implemented by third_party/fdlibm |
364 "atan2", MathAtan2JS, | 357 "atan2", MathAtan2JS, |
365 "pow", MathPow, | 358 "pow", MathPow, |
366 "max", MathMax, | 359 "max", MathMax, |
367 "min", MathMin, | 360 "min", MathMin, |
368 "imul", MathImul, | 361 "imul", MathImul, |
369 "sign", MathSign, | 362 "sign", MathSign, |
370 "trunc", MathTrunc, | 363 "trunc", MathTrunc, |
371 "sinh", MathSinh, // implemented by third_party/fdlibm | 364 "sinh", MathSinh, // implemented by third_party/fdlibm |
372 "cosh", MathCosh, | 365 "cosh", MathCosh, // implemented by third_party/fdlibm |
373 "tanh", MathTanh, | 366 "tanh", MathTanh, |
374 "asinh", MathAsinh, | 367 "asinh", MathAsinh, |
375 "acosh", MathAcosh, | 368 "acosh", MathAcosh, |
376 "atanh", MathAtanh, | 369 "atanh", MathAtanh, |
377 "log10", MathLog10, | 370 "log10", MathLog10, |
378 "log2", MathLog2, | 371 "log2", MathLog2, |
379 "hypot", MathHypot, | 372 "hypot", MathHypot, |
380 "fround", MathFroundJS, | 373 "fround", MathFroundJS, |
381 "clz32", MathClz32, | 374 "clz32", MathClz32, |
382 "cbrt", MathCbrt, | 375 "cbrt", MathCbrt, |
383 "log1p", MathLog1p, // implemented by third_party/fdlibm | 376 "log1p", MathLog1p, // implemented by third_party/fdlibm |
384 "expm1", MathExpm1 // implemented by third_party/fdlibm | 377 "expm1", MathExpm1 // implemented by third_party/fdlibm |
385 )); | 378 )); |
386 | 379 |
387 %SetInlineBuiltinFlag(MathCeil); | 380 %SetInlineBuiltinFlag(MathCeil); |
388 %SetInlineBuiltinFlag(MathRandom); | 381 %SetInlineBuiltinFlag(MathRandom); |
389 %SetInlineBuiltinFlag(MathSin); | 382 %SetInlineBuiltinFlag(MathSin); |
390 %SetInlineBuiltinFlag(MathCos); | 383 %SetInlineBuiltinFlag(MathCos); |
391 } | 384 } |
392 | 385 |
393 SetUpMath(); | 386 SetUpMath(); |
OLD | NEW |