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

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

Issue 739913003: Implement log10 via fdlibm port. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressed comments Created 6 years, 1 month 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
« no previous file with comments | « src/third_party/fdlibm/fdlibm.cc ('k') | test/mjsunit/es6/math-log2-log10.js » ('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 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 // |x| in [log(maxdouble), overflowthreshold] 805 // |x| in [log(maxdouble), overflowthreshold]
806 if (MathAbs(x) <= KCOSH_OVERFLOW) { 806 if (MathAbs(x) <= KCOSH_OVERFLOW) {
807 var w = MathExp(0.5 * MathAbs(x)); 807 var w = MathExp(0.5 * MathAbs(x));
808 var t = 0.5 * w; 808 var t = 0.5 * w;
809 return t * w; 809 return t * w;
810 } 810 }
811 if (NUMBER_IS_NAN(x)) return x; 811 if (NUMBER_IS_NAN(x)) return x;
812 // |x| > overflowthreshold. 812 // |x| > overflowthreshold.
813 return INFINITY; 813 return INFINITY;
814 } 814 }
815
816 // ES6 draft 09-27-13, section 20.2.2.21.
817 // Return the base 10 logarithm of x
818 //
819 // Method :
820 // Let log10_2hi = leading 40 bits of log10(2) and
821 // log10_2lo = log10(2) - log10_2hi,
822 // ivln10 = 1/log(10) rounded.
823 // Then
824 // n = ilogb(x),
825 // if(n<0) n = n+1;
826 // x = scalbn(x,-n);
827 // log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x))
828 //
829 // Note 1:
830 // To guarantee log10(10**n)=n, where 10**n is normal, the rounding
831 // mode must set to Round-to-Nearest.
832 // Note 2:
833 // [1/log(10)] rounded to 53 bits has error .198 ulps;
834 // log10 is monotonic at all binary break points.
835 //
836 // Special cases:
837 // log10(x) is NaN if x < 0;
838 // log10(+INF) is +INF; log10(0) is -INF;
839 // log10(NaN) is that NaN;
840 // log10(10**N) = N for N=0,1,...,22.
841 //
842
843 const IVLN10 = kMath[53];
844 const LOG10_2HI = kMath[54];
845 const LOG10_2LO = kMath[55];
846
847 function MathLog10(x) {
848 x = x * 1; // Convert to number.
849 var hx = %_DoubleHi(x);
850 var lx = %_DoubleLo(x);
851 var k = 0;
852
853 if (hx < 0x00100000) {
854 // x < 2^-1022
855 // log10(+/- 0) = -Infinity.
856 if (((hx & 0x7fffffff) | lx) === 0) return -INFINITY;
857 // log10 of negative number is NaN.
858 if (hx < 0) return NAN;
859 // Subnormal number. Scale up x.
860 k -= 54;
861 x *= TWO54;
862 hx = %_DoubleHi(x);
863 lx = %_DoubleLo(x);
864 }
865
866 // Infinity or NaN.
867 if (hx >= 0x7ff00000) return x;
868
869 k += (hx >> 20) - 1023;
870 i = (k & 0x80000000) >> 31;
871 hx = (hx & 0x000fffff) | ((0x3ff - i) << 20);
872 y = k + i;
873 x = %_ConstructDouble(hx, lx);
874
875 z = y * LOG10_2LO + IVLN10 * MathLog(x);
876 return z + y * LOG10_2HI;
877 }
OLDNEW
« no previous file with comments | « src/third_party/fdlibm/fdlibm.cc ('k') | test/mjsunit/es6/math-log2-log10.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698