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 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 // t = 2^-k | 703 // t = 2^-k |
704 t = %_ConstructDouble((0x3ff - k) << 20, 0); | 704 t = %_ConstructDouble((0x3ff - k) << 20, 0); |
705 y = x - (e + t); | 705 y = x - (e + t); |
706 y += 1; | 706 y += 1; |
707 // Add k to y's exponent | 707 // Add k to y's exponent |
708 y = %_ConstructDouble(%_DoubleHi(y) + (k << 20), %_DoubleLo(y)); | 708 y = %_ConstructDouble(%_DoubleHi(y) + (k << 20), %_DoubleLo(y)); |
709 } | 709 } |
710 } | 710 } |
711 return y; | 711 return y; |
712 } | 712 } |
713 | |
714 | |
715 // ES6 draft 09-27-13, section 20.2.2.30. | |
716 // Math.sinh | |
717 // Method : | |
718 // mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2 | |
719 // 1. Replace x by |x| (sinh(-x) = -sinh(x)). | |
720 // 2. | |
721 // E + E/(E+1) | |
722 // 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x) | |
723 // 2 | |
724 // | |
725 // 22 <= x <= lnovft : sinh(x) := exp(x)/2 | |
726 // lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2) | |
727 // ln2ovft < x : sinh(x) := x*shuge (overflow) | |
728 // | |
729 // Special cases: | |
730 // sinh(x) is |x| if x is +Infinity, -Infinity, or NaN. | |
731 // only sinh(0)=0 is exact for finite x. | |
732 // | |
733 const KSINH_OVERFLOW = kMath[52]; | |
Raymond Toy
2014/08/27 16:22:02
Why is KSINH_OVERFLOW an element of kMath, but TWO
Yang
2014/08/28 07:18:08
TWO_M28 and LOG_MAXD have empty lower halves, so t
Raymond Toy
2014/08/28 17:15:55
Ok.
| |
734 const TWO_M28 = 3.725290298461914e-9; // 2^-28, empty lower half | |
735 const LOG_MAXD = 709.7822265625; // 0x40862e42 00000000, empty lower half | |
736 | |
737 function MathSinh(x) { | |
738 x = x * 1; // Convert to number. | |
739 var h = (x < 0) ? -0.5 : 0.5; | |
740 // |x| in [0, 22]. return sign(x)*0.5*(E+E/(E+1)) | |
741 var ax = MathAbs(x); | |
742 if (ax < 22) { | |
743 // For |x| < 2^-28, sinh(x) = x | |
744 if (ax < TWO_M28) return x; | |
745 var t = MathExpm1(ax); | |
746 if (ax < 1) return h * (2 * t - t * t / (t + 1)); | |
747 return h * (t + t / (t + 1)); | |
748 } | |
749 // |x| in [22, log(maxdouble)], return 0.5 * exp(|x|) | |
750 if (ax < LOG_MAXD) return h * MathExp(ax); | |
751 // |x| in [log(maxdouble), overflowthreshold] | |
752 // overflowthreshold = 710.4758600739426 | |
753 if (ax <= KSINH_OVERFLOW) { | |
754 var w = MathExp(0.5 * ax); | |
755 var t = h * w; | |
756 return t * w; | |
757 } | |
758 // |x| > overflowthreshold or is NaN. | |
759 // Return Infinity of the appropriate sign or NaN. | |
760 return x * INFINITY; | |
761 } | |
OLD | NEW |