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

Side by Side Diff: fusl/src/math/log10f.c

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 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
OLDNEW
1 /* origin: FreeBSD /usr/src/lib/msun/src/e_log10f.c */ 1 /* origin: FreeBSD /usr/src/lib/msun/src/e_log10f.c */
2 /* 2 /*
3 * ==================================================== 3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * 5 *
6 * Developed at SunPro, a Sun Microsystems, Inc. business. 6 * Developed at SunPro, 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 * ====================================================
11 */ 11 */
12 /* 12 /*
13 * See comments in log10.c. 13 * See comments in log10.c.
14 */ 14 */
15 15
16 #include <math.h> 16 #include <math.h>
17 #include <stdint.h> 17 #include <stdint.h>
18 18
19 static const float 19 static const float ivln10hi = 4.3432617188e-01, /* 0x3ede6000 */
20 ivln10hi = 4.3432617188e-01, /* 0x3ede6000 */ 20 ivln10lo = -3.1689971365e-05, /* 0xb804ead9 */
21 ivln10lo = -3.1689971365e-05, /* 0xb804ead9 */ 21 log10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */
22 log10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */ 22 log10_2lo = 7.9034151668e-07, /* 0x355427db */
23 log10_2lo = 7.9034151668e-07, /* 0x355427db */ 23 /* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */
24 /* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */ 24 Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */
25 Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */ 25 Lg2 = 0xccce13.0p-25, /* 0.40000972152 */
26 Lg2 = 0xccce13.0p-25, /* 0.40000972152 */ 26 Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */
27 Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */ 27 Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */
28 Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */
29 28
30 float log10f(float x) 29 float log10f(float x) {
31 { 30 union {
32 » union {float f; uint32_t i;} u = {x}; 31 float f;
33 » float_t hfsq,f,s,z,R,w,t1,t2,dk,hi,lo; 32 uint32_t i;
34 » uint32_t ix; 33 } u = {x};
35 » int k; 34 float_t hfsq, f, s, z, R, w, t1, t2, dk, hi, lo;
35 uint32_t ix;
36 int k;
36 37
37 » ix = u.i; 38 ix = u.i;
38 » k = 0; 39 k = 0;
39 » if (ix < 0x00800000 || ix>>31) { /* x < 2**-126 */ 40 if (ix < 0x00800000 || ix >> 31) { /* x < 2**-126 */
40 » » if (ix<<1 == 0) 41 if (ix << 1 == 0)
41 » » » return -1/(x*x); /* log(+-0)=-inf */ 42 return -1 / (x * x); /* log(+-0)=-inf */
42 » » if (ix>>31) 43 if (ix >> 31)
43 » » » return (x-x)/0.0f; /* log(-#) = NaN */ 44 return (x - x) / 0.0f; /* log(-#) = NaN */
44 » » /* subnormal number, scale up x */ 45 /* subnormal number, scale up x */
45 » » k -= 25; 46 k -= 25;
46 » » x *= 0x1p25f; 47 x *= 0x1p25f;
47 » » u.f = x; 48 u.f = x;
48 » » ix = u.i; 49 ix = u.i;
49 » } else if (ix >= 0x7f800000) { 50 } else if (ix >= 0x7f800000) {
50 » » return x; 51 return x;
51 » } else if (ix == 0x3f800000) 52 } else if (ix == 0x3f800000)
52 » » return 0; 53 return 0;
53 54
54 » /* reduce x into [sqrt(2)/2, sqrt(2)] */ 55 /* reduce x into [sqrt(2)/2, sqrt(2)] */
55 » ix += 0x3f800000 - 0x3f3504f3; 56 ix += 0x3f800000 - 0x3f3504f3;
56 » k += (int)(ix>>23) - 0x7f; 57 k += (int)(ix >> 23) - 0x7f;
57 » ix = (ix&0x007fffff) + 0x3f3504f3; 58 ix = (ix & 0x007fffff) + 0x3f3504f3;
58 » u.i = ix; 59 u.i = ix;
59 » x = u.f; 60 x = u.f;
60 61
61 » f = x - 1.0f; 62 f = x - 1.0f;
62 » s = f/(2.0f + f); 63 s = f / (2.0f + f);
63 » z = s*s; 64 z = s * s;
64 » w = z*z; 65 w = z * z;
65 » t1= w*(Lg2+w*Lg4); 66 t1 = w * (Lg2 + w * Lg4);
66 » t2= z*(Lg1+w*Lg3); 67 t2 = z * (Lg1 + w * Lg3);
67 » R = t2 + t1; 68 R = t2 + t1;
68 » hfsq = 0.5f*f*f; 69 hfsq = 0.5f * f * f;
69 70
70 » hi = f - hfsq; 71 hi = f - hfsq;
71 » u.f = hi; 72 u.f = hi;
72 » u.i &= 0xfffff000; 73 u.i &= 0xfffff000;
73 » hi = u.f; 74 hi = u.f;
74 » lo = f - hi - hfsq + s*(hfsq+R); 75 lo = f - hi - hfsq + s * (hfsq + R);
75 » dk = k; 76 dk = k;
76 » return dk*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi + hi*ivln10hi + dk* log10_2hi; 77 return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi +
78 dk * log10_2hi;
77 } 79 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698