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

Side by Side Diff: fusl/src/math/exp.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_exp.c */ 1 /* origin: FreeBSD /usr/src/lib/msun/src/e_exp.c */
2 /* 2 /*
3 * ==================================================== 3 * ====================================================
4 * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. 4 * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
5 * 5 *
6 * Permission to use, copy, modify, and distribute this 6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice 7 * software is freely granted, provided that this notice
8 * is preserved. 8 * is preserved.
9 * ==================================================== 9 * ====================================================
10 */ 10 */
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 * 1 ulp (unit in the last place). 60 * 1 ulp (unit in the last place).
61 * 61 *
62 * Misc. info. 62 * Misc. info.
63 * For IEEE double 63 * For IEEE double
64 * if x > 709.782712893383973096 then exp(x) overflows 64 * if x > 709.782712893383973096 then exp(x) overflows
65 * if x < -745.133219101941108420 then exp(x) underflows 65 * if x < -745.133219101941108420 then exp(x) underflows
66 */ 66 */
67 67
68 #include "libm.h" 68 #include "libm.h"
69 69
70 static const double 70 static const double half[2] = {0.5, -0.5},
71 half[2] = {0.5,-0.5}, 71 ln2hi =
72 ln2hi = 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */ 72 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */
73 ln2lo = 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */ 73 ln2lo = 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */
74 invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */ 74 invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */
75 P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ 75 P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
76 P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ 76 P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
77 P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ 77 P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
78 P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ 78 P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
79 P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */ 79 P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
80 80
81 double exp(double x) 81 double exp(double x) {
82 { 82 double_t hi, lo, c, xx, y;
83 » double_t hi, lo, c, xx, y; 83 int k, sign;
84 » int k, sign; 84 uint32_t hx;
85 » uint32_t hx;
86 85
87 » GET_HIGH_WORD(hx, x); 86 GET_HIGH_WORD(hx, x);
88 » sign = hx>>31; 87 sign = hx >> 31;
89 » hx &= 0x7fffffff; /* high word of |x| */ 88 hx &= 0x7fffffff; /* high word of |x| */
90 89
91 » /* special cases */ 90 /* special cases */
92 » if (hx >= 0x4086232b) { /* if |x| >= 708.39... */ 91 if (hx >= 0x4086232b) { /* if |x| >= 708.39... */
93 » » if (isnan(x)) 92 if (isnan(x))
94 » » » return x; 93 return x;
95 » » if (x > 709.782712893383973096) { 94 if (x > 709.782712893383973096) {
96 » » » /* overflow if x!=inf */ 95 /* overflow if x!=inf */
97 » » » x *= 0x1p1023; 96 x *= 0x1p1023;
98 » » » return x; 97 return x;
99 » » } 98 }
100 » » if (x < -708.39641853226410622) { 99 if (x < -708.39641853226410622) {
101 » » » /* underflow if x!=-inf */ 100 /* underflow if x!=-inf */
102 » » » FORCE_EVAL((float)(-0x1p-149/x)); 101 FORCE_EVAL((float)(-0x1p-149 / x));
103 » » » if (x < -745.13321910194110842) 102 if (x < -745.13321910194110842)
104 » » » » return 0; 103 return 0;
105 » » } 104 }
106 » } 105 }
107 106
108 » /* argument reduction */ 107 /* argument reduction */
109 » if (hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ 108 if (hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */
110 » » if (hx >= 0x3ff0a2b2) /* if |x| >= 1.5 ln2 */ 109 if (hx >= 0x3ff0a2b2) /* if |x| >= 1.5 ln2 */
111 » » » k = (int)(invln2*x + half[sign]); 110 k = (int)(invln2 * x + half[sign]);
112 » » else 111 else
113 » » » k = 1 - sign - sign; 112 k = 1 - sign - sign;
114 » » hi = x - k*ln2hi; /* k*ln2hi is exact here */ 113 hi = x - k * ln2hi; /* k*ln2hi is exact here */
115 » » lo = k*ln2lo; 114 lo = k * ln2lo;
116 » » x = hi - lo; 115 x = hi - lo;
117 » } else if (hx > 0x3e300000) { /* if |x| > 2**-28 */ 116 } else if (hx > 0x3e300000) { /* if |x| > 2**-28 */
118 » » k = 0; 117 k = 0;
119 » » hi = x; 118 hi = x;
120 » » lo = 0; 119 lo = 0;
121 » } else { 120 } else {
122 » » /* inexact if x!=0 */ 121 /* inexact if x!=0 */
123 » » FORCE_EVAL(0x1p1023 + x); 122 FORCE_EVAL(0x1p1023 + x);
124 » » return 1 + x; 123 return 1 + x;
125 » } 124 }
126 125
127 » /* x is now in primary range */ 126 /* x is now in primary range */
128 » xx = x*x; 127 xx = x * x;
129 » c = x - xx*(P1+xx*(P2+xx*(P3+xx*(P4+xx*P5)))); 128 c = x - xx * (P1 + xx * (P2 + xx * (P3 + xx * (P4 + xx * P5))));
130 » y = 1 + (x*c/(2-c) - lo + hi); 129 y = 1 + (x * c / (2 - c) - lo + hi);
131 » if (k == 0) 130 if (k == 0)
132 » » return y; 131 return y;
133 » return scalbn(y, k); 132 return scalbn(y, k);
134 } 133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698