| OLD | NEW |
| 1 // The following is adapted from fdlibm (http://www.netlib.org/fdlibm), | 1 // The following is adapted from fdlibm (http://www.netlib.org/fdlibm), |
| 2 // | 2 // |
| 3 // ==================================================== | 3 // ==================================================== |
| 4 // Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved. | 4 // Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved. |
| 5 // | 5 // |
| 6 // Developed at SunSoft, a Sun Microsystems, Inc. business. | 6 // Developed at SunSoft, a Sun Microsystems, Inc. business. |
| 7 // Permission to use, copy, modify, and distribute this | 7 // Permission to use, copy, modify, and distribute this |
| 8 // software is freely granted, provided that this notice | 8 // software is freely granted, provided that this notice |
| 9 // is preserved. | 9 // is preserved. |
| 10 // ==================================================== | 10 // ==================================================== |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 "use strict"; | 24 "use strict"; |
| 25 | 25 |
| 26 %CheckIsBootstrapping(); | 26 %CheckIsBootstrapping(); |
| 27 | 27 |
| 28 // ------------------------------------------------------------------- | 28 // ------------------------------------------------------------------- |
| 29 // Imports | 29 // Imports |
| 30 | 30 |
| 31 var GlobalFloat64Array = global.Float64Array; | 31 var GlobalFloat64Array = global.Float64Array; |
| 32 var GlobalMath = global.Math; | 32 var GlobalMath = global.Math; |
| 33 var MathAbs; | 33 var MathAbs; |
| 34 var MathExp; |
| 34 var NaN = %GetRootNaN(); | 35 var NaN = %GetRootNaN(); |
| 35 var rempio2result; | 36 var rempio2result; |
| 36 | 37 |
| 37 utils.Import(function(from) { | 38 utils.Import(function(from) { |
| 38 MathAbs = from.MathAbs; | 39 MathAbs = from.MathAbs; |
| 40 MathExp = from.MathExp; |
| 39 }); | 41 }); |
| 40 | 42 |
| 41 utils.CreateDoubleResultArray = function(global) { | 43 utils.CreateDoubleResultArray = function(global) { |
| 42 rempio2result = new GlobalFloat64Array(2); | 44 rempio2result = new GlobalFloat64Array(2); |
| 43 }; | 45 }; |
| 44 | 46 |
| 45 // ------------------------------------------------------------------- | 47 // ------------------------------------------------------------------- |
| 46 | 48 |
| 47 define INVPIO2 = 6.36619772367581382433e-01; | 49 define INVPIO2 = 6.36619772367581382433e-01; |
| 48 define PIO2_1 = 1.57079632673412561417; | 50 define PIO2_1 = 1.57079632673412561417; |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 // |x| in [0, 22]. return sign(x)*0.5*(E+E/(E+1)) | 627 // |x| in [0, 22]. return sign(x)*0.5*(E+E/(E+1)) |
| 626 var ax = MathAbs(x); | 628 var ax = MathAbs(x); |
| 627 if (ax < 22) { | 629 if (ax < 22) { |
| 628 // For |x| < 2^-28, sinh(x) = x | 630 // For |x| < 2^-28, sinh(x) = x |
| 629 if (ax < TWO_M28) return x; | 631 if (ax < TWO_M28) return x; |
| 630 var t = MathExpm1(ax); | 632 var t = MathExpm1(ax); |
| 631 if (ax < 1) return h * (2 * t - t * t / (t + 1)); | 633 if (ax < 1) return h * (2 * t - t * t / (t + 1)); |
| 632 return h * (t + t / (t + 1)); | 634 return h * (t + t / (t + 1)); |
| 633 } | 635 } |
| 634 // |x| in [22, log(maxdouble)], return 0.5 * exp(|x|) | 636 // |x| in [22, log(maxdouble)], return 0.5 * exp(|x|) |
| 635 if (ax < LOG_MAXD) return h * %math_exp(ax); | 637 if (ax < LOG_MAXD) return h * MathExp(ax); |
| 636 // |x| in [log(maxdouble), overflowthreshold] | 638 // |x| in [log(maxdouble), overflowthreshold] |
| 637 // overflowthreshold = 710.4758600739426 | 639 // overflowthreshold = 710.4758600739426 |
| 638 if (ax <= KSINH_OVERFLOW) { | 640 if (ax <= KSINH_OVERFLOW) { |
| 639 var w = %math_exp(0.5 * ax); | 641 var w = MathExp(0.5 * ax); |
| 640 var t = h * w; | 642 var t = h * w; |
| 641 return t * w; | 643 return t * w; |
| 642 } | 644 } |
| 643 // |x| > overflowthreshold or is NaN. | 645 // |x| > overflowthreshold or is NaN. |
| 644 // Return Infinity of the appropriate sign or NaN. | 646 // Return Infinity of the appropriate sign or NaN. |
| 645 return x * INFINITY; | 647 return x * INFINITY; |
| 646 } | 648 } |
| 647 | 649 |
| 648 | 650 |
| 649 // ES6 draft 09-27-13, section 20.2.2.12. | 651 // ES6 draft 09-27-13, section 20.2.2.12. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 675 // |x| in [0,0.5*log2], return 1+expm1(|x|)^2/(2*exp(|x|)) | 677 // |x| in [0,0.5*log2], return 1+expm1(|x|)^2/(2*exp(|x|)) |
| 676 if (ix < 0x3fd62e43) { | 678 if (ix < 0x3fd62e43) { |
| 677 var t = MathExpm1(MathAbs(x)); | 679 var t = MathExpm1(MathAbs(x)); |
| 678 var w = 1 + t; | 680 var w = 1 + t; |
| 679 // For |x| < 2^-55, cosh(x) = 1 | 681 // For |x| < 2^-55, cosh(x) = 1 |
| 680 if (ix < 0x3c800000) return w; | 682 if (ix < 0x3c800000) return w; |
| 681 return 1 + (t * t) / (w + w); | 683 return 1 + (t * t) / (w + w); |
| 682 } | 684 } |
| 683 // |x| in [0.5*log2, 22], return (exp(|x|)+1/exp(|x|)/2 | 685 // |x| in [0.5*log2, 22], return (exp(|x|)+1/exp(|x|)/2 |
| 684 if (ix < 0x40360000) { | 686 if (ix < 0x40360000) { |
| 685 var t = %math_exp(MathAbs(x)); | 687 var t = MathExp(MathAbs(x)); |
| 686 return 0.5 * t + 0.5 / t; | 688 return 0.5 * t + 0.5 / t; |
| 687 } | 689 } |
| 688 // |x| in [22, log(maxdouble)], return half*exp(|x|) | 690 // |x| in [22, log(maxdouble)], return half*exp(|x|) |
| 689 if (ix < 0x40862e42) return 0.5 * %math_exp(MathAbs(x)); | 691 if (ix < 0x40862e42) return 0.5 * MathExp(MathAbs(x)); |
| 690 // |x| in [log(maxdouble), overflowthreshold] | 692 // |x| in [log(maxdouble), overflowthreshold] |
| 691 if (MathAbs(x) <= KCOSH_OVERFLOW) { | 693 if (MathAbs(x) <= KCOSH_OVERFLOW) { |
| 692 var w = %math_exp(0.5 * MathAbs(x)); | 694 var w = MathExp(0.5 * MathAbs(x)); |
| 693 var t = 0.5 * w; | 695 var t = 0.5 * w; |
| 694 return t * w; | 696 return t * w; |
| 695 } | 697 } |
| 696 if (NUMBER_IS_NAN(x)) return x; | 698 if (NUMBER_IS_NAN(x)) return x; |
| 697 // |x| > overflowthreshold. | 699 // |x| > overflowthreshold. |
| 698 return INFINITY; | 700 return INFINITY; |
| 699 } | 701 } |
| 700 | 702 |
| 701 // ES6 draft 09-27-13, section 20.2.2.33. | 703 // ES6 draft 09-27-13, section 20.2.2.33. |
| 702 // Math.tanh(x) | 704 // Math.tanh(x) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 "sinh", MathSinh, | 766 "sinh", MathSinh, |
| 765 "cosh", MathCosh, | 767 "cosh", MathCosh, |
| 766 "tanh", MathTanh, | 768 "tanh", MathTanh, |
| 767 "expm1", MathExpm1 | 769 "expm1", MathExpm1 |
| 768 ]); | 770 ]); |
| 769 | 771 |
| 770 %SetForceInlineFlag(MathSin); | 772 %SetForceInlineFlag(MathSin); |
| 771 %SetForceInlineFlag(MathCos); | 773 %SetForceInlineFlag(MathCos); |
| 772 | 774 |
| 773 }) | 775 }) |
| OLD | NEW |