Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: third_party/fdlibm/fdlibm.js

Issue 522723002: Port fdlibm implementation for Math.cosh. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/fdlibm/fdlibm.cc ('k') | tools/generate-runtime-tests.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 // overflowthreshold = 710.4758600739426 752 // overflowthreshold = 710.4758600739426
753 if (ax <= KSINH_OVERFLOW) { 753 if (ax <= KSINH_OVERFLOW) {
754 var w = MathExp(0.5 * ax); 754 var w = MathExp(0.5 * ax);
755 var t = h * w; 755 var t = h * w;
756 return t * w; 756 return t * w;
757 } 757 }
758 // |x| > overflowthreshold or is NaN. 758 // |x| > overflowthreshold or is NaN.
759 // Return Infinity of the appropriate sign or NaN. 759 // Return Infinity of the appropriate sign or NaN.
760 return x * INFINITY; 760 return x * INFINITY;
761 } 761 }
762
763
764 // ES6 draft 09-27-13, section 20.2.2.12.
765 // Math.cosh
766 // Method :
767 // mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2
768 // 1. Replace x by |x| (cosh(x) = cosh(-x)).
769 // 2.
770 // [ exp(x) - 1 ]^2
771 // 0 <= x <= ln2/2 : cosh(x) := 1 + -------------------
772 // 2*exp(x)
773 //
774 // exp(x) + 1/exp(x)
775 // ln2/2 <= x <= 22 : cosh(x) := -------------------
776 // 2
777 // 22 <= x <= lnovft : cosh(x) := exp(x)/2
778 // lnovft <= x <= ln2ovft: cosh(x) := exp(x/2)/2 * exp(x/2)
779 // ln2ovft < x : cosh(x) := huge*huge (overflow)
780 //
781 // Special cases:
782 // cosh(x) is |x| if x is +INF, -INF, or NaN.
783 // only cosh(0)=1 is exact for finite x.
784 //
785 const KCOSH_OVERFLOW = kMath[52];
786
787 function MathCosh(x) {
788 x = x * 1; // Convert to number.
789 var ix = %_DoubleHi(x) & 0x7fffffff;
790 // |x| in [0,0.5*log2], return 1+expm1(|x|)^2/(2*exp(|x|))
791 if (ix < 0x3fd62e43) {
792 var t = MathExpm1(MathAbs(x));
793 var w = 1 + t;
794 // For |x| < 2^-55, cosh(x) = 1
795 if (ix < 0x3c800000) return w;
796 return 1 + (t * t) / (w + w);
797 }
798 // |x| in [0.5*log2, 22], return (exp(|x|)+1/exp(|x|)/2
799 if (ix < 0x40360000) {
800 var t = MathExp(MathAbs(x));
801 return 0.5 * t + 0.5 / t;
802 }
803 // |x| in [22, log(maxdouble)], return half*exp(|x|)
804 if (ix < 0x40862e42) return 0.5 * MathExp(MathAbs(x));
805 // |x| in [log(maxdouble), overflowthreshold]
806 if (MathAbs(x) <= KCOSH_OVERFLOW) {
807 var w = MathExp(0.5 * MathAbs(x));
808 var t = 0.5 * w;
809 return t * w;
810 }
811 if (NUMBER_IS_NAN(x)) return x;
812 // |x| > overflowthreshold.
813 return INFINITY;
814 }
OLDNEW
« no previous file with comments | « third_party/fdlibm/fdlibm.cc ('k') | tools/generate-runtime-tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698