| 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; | |
| 35 var NaN = %GetRootNaN(); | 34 var NaN = %GetRootNaN(); |
| 36 var rempio2result; | 35 var rempio2result; |
| 37 | 36 |
| 38 utils.Import(function(from) { | 37 utils.Import(function(from) { |
| 39 MathAbs = from.MathAbs; | 38 MathAbs = from.MathAbs; |
| 40 MathExp = from.MathExp; | |
| 41 }); | 39 }); |
| 42 | 40 |
| 43 utils.CreateDoubleResultArray = function(global) { | 41 utils.CreateDoubleResultArray = function(global) { |
| 44 rempio2result = new GlobalFloat64Array(2); | 42 rempio2result = new GlobalFloat64Array(2); |
| 45 }; | 43 }; |
| 46 | 44 |
| 47 // ------------------------------------------------------------------- | 45 // ------------------------------------------------------------------- |
| 48 | 46 |
| 49 define INVPIO2 = 6.36619772367581382433e-01; | 47 define INVPIO2 = 6.36619772367581382433e-01; |
| 50 define PIO2_1 = 1.57079632673412561417; | 48 define PIO2_1 = 1.57079632673412561417; |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 // |x| in [0, 22]. return sign(x)*0.5*(E+E/(E+1)) | 625 // |x| in [0, 22]. return sign(x)*0.5*(E+E/(E+1)) |
| 628 var ax = MathAbs(x); | 626 var ax = MathAbs(x); |
| 629 if (ax < 22) { | 627 if (ax < 22) { |
| 630 // For |x| < 2^-28, sinh(x) = x | 628 // For |x| < 2^-28, sinh(x) = x |
| 631 if (ax < TWO_M28) return x; | 629 if (ax < TWO_M28) return x; |
| 632 var t = MathExpm1(ax); | 630 var t = MathExpm1(ax); |
| 633 if (ax < 1) return h * (2 * t - t * t / (t + 1)); | 631 if (ax < 1) return h * (2 * t - t * t / (t + 1)); |
| 634 return h * (t + t / (t + 1)); | 632 return h * (t + t / (t + 1)); |
| 635 } | 633 } |
| 636 // |x| in [22, log(maxdouble)], return 0.5 * exp(|x|) | 634 // |x| in [22, log(maxdouble)], return 0.5 * exp(|x|) |
| 637 if (ax < LOG_MAXD) return h * MathExp(ax); | 635 if (ax < LOG_MAXD) return h * %math_exp(ax); |
| 638 // |x| in [log(maxdouble), overflowthreshold] | 636 // |x| in [log(maxdouble), overflowthreshold] |
| 639 // overflowthreshold = 710.4758600739426 | 637 // overflowthreshold = 710.4758600739426 |
| 640 if (ax <= KSINH_OVERFLOW) { | 638 if (ax <= KSINH_OVERFLOW) { |
| 641 var w = MathExp(0.5 * ax); | 639 var w = %math_exp(0.5 * ax); |
| 642 var t = h * w; | 640 var t = h * w; |
| 643 return t * w; | 641 return t * w; |
| 644 } | 642 } |
| 645 // |x| > overflowthreshold or is NaN. | 643 // |x| > overflowthreshold or is NaN. |
| 646 // Return Infinity of the appropriate sign or NaN. | 644 // Return Infinity of the appropriate sign or NaN. |
| 647 return x * INFINITY; | 645 return x * INFINITY; |
| 648 } | 646 } |
| 649 | 647 |
| 650 | 648 |
| 651 // ES6 draft 09-27-13, section 20.2.2.12. | 649 // ES6 draft 09-27-13, section 20.2.2.12. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 677 // |x| in [0,0.5*log2], return 1+expm1(|x|)^2/(2*exp(|x|)) | 675 // |x| in [0,0.5*log2], return 1+expm1(|x|)^2/(2*exp(|x|)) |
| 678 if (ix < 0x3fd62e43) { | 676 if (ix < 0x3fd62e43) { |
| 679 var t = MathExpm1(MathAbs(x)); | 677 var t = MathExpm1(MathAbs(x)); |
| 680 var w = 1 + t; | 678 var w = 1 + t; |
| 681 // For |x| < 2^-55, cosh(x) = 1 | 679 // For |x| < 2^-55, cosh(x) = 1 |
| 682 if (ix < 0x3c800000) return w; | 680 if (ix < 0x3c800000) return w; |
| 683 return 1 + (t * t) / (w + w); | 681 return 1 + (t * t) / (w + w); |
| 684 } | 682 } |
| 685 // |x| in [0.5*log2, 22], return (exp(|x|)+1/exp(|x|)/2 | 683 // |x| in [0.5*log2, 22], return (exp(|x|)+1/exp(|x|)/2 |
| 686 if (ix < 0x40360000) { | 684 if (ix < 0x40360000) { |
| 687 var t = MathExp(MathAbs(x)); | 685 var t = %math_exp(MathAbs(x)); |
| 688 return 0.5 * t + 0.5 / t; | 686 return 0.5 * t + 0.5 / t; |
| 689 } | 687 } |
| 690 // |x| in [22, log(maxdouble)], return half*exp(|x|) | 688 // |x| in [22, log(maxdouble)], return half*exp(|x|) |
| 691 if (ix < 0x40862e42) return 0.5 * MathExp(MathAbs(x)); | 689 if (ix < 0x40862e42) return 0.5 * %math_exp(MathAbs(x)); |
| 692 // |x| in [log(maxdouble), overflowthreshold] | 690 // |x| in [log(maxdouble), overflowthreshold] |
| 693 if (MathAbs(x) <= KCOSH_OVERFLOW) { | 691 if (MathAbs(x) <= KCOSH_OVERFLOW) { |
| 694 var w = MathExp(0.5 * MathAbs(x)); | 692 var w = %math_exp(0.5 * MathAbs(x)); |
| 695 var t = 0.5 * w; | 693 var t = 0.5 * w; |
| 696 return t * w; | 694 return t * w; |
| 697 } | 695 } |
| 698 if (NUMBER_IS_NAN(x)) return x; | 696 if (NUMBER_IS_NAN(x)) return x; |
| 699 // |x| > overflowthreshold. | 697 // |x| > overflowthreshold. |
| 700 return INFINITY; | 698 return INFINITY; |
| 701 } | 699 } |
| 702 | 700 |
| 703 // ES6 draft 09-27-13, section 20.2.2.33. | 701 // ES6 draft 09-27-13, section 20.2.2.33. |
| 704 // Math.tanh(x) | 702 // Math.tanh(x) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 "sinh", MathSinh, | 764 "sinh", MathSinh, |
| 767 "cosh", MathCosh, | 765 "cosh", MathCosh, |
| 768 "tanh", MathTanh, | 766 "tanh", MathTanh, |
| 769 "expm1", MathExpm1 | 767 "expm1", MathExpm1 |
| 770 ]); | 768 ]); |
| 771 | 769 |
| 772 %SetForceInlineFlag(MathSin); | 770 %SetForceInlineFlag(MathSin); |
| 773 %SetForceInlineFlag(MathCos); | 771 %SetForceInlineFlag(MathCos); |
| 774 | 772 |
| 775 }) | 773 }) |
| OLD | NEW |