Files
amath/doc/man/man3/expm1.c.3
T
2017-01-24 22:03:15 +01:00

255 lines
6.7 KiB
Plaintext

.TH "lib/real/expm1.c" 3 "Tue Jan 24 2017" "Version 1.6.2" "amath" \" -*- nroff -*-
.ad l
.nh
.SH NAME
lib/real/expm1.c \-
.SH SYNOPSIS
.br
.PP
\fC#include 'prim\&.h'\fP
.br
\fC#include 'math\&.h'\fP
.br
.SS "Functions"
.in +1c
.ti -1c
.RI "double \fBexpm1\fP (double x)"
.br
.in -1c
.SS "Variables"
.in +1c
.ti -1c
.RI "static const double \fBone\fP = 1\&.0"
.br
.ti -1c
.RI "static const double \fBhuge\fP = 1\&.0e+300"
.br
.ti -1c
.RI "static const double \fBtiny\fP = 1\&.0e\-300"
.br
.ti -1c
.RI "static const double \fBo_threshold\fP = 7\&.09782712893383973096e+02"
.br
.ti -1c
.RI "static const double \fBln2_hi\fP = 6\&.93147180369123816490e\-01"
.br
.ti -1c
.RI "static const double \fBln2_lo\fP = 1\&.90821492927058770002e\-10"
.br
.ti -1c
.RI "static const double \fBinvln2\fP = 1\&.44269504088896338700e+00"
.br
.ti -1c
.RI "static const double \fBQ1\fP = \-3\&.33333333333331316428e\-02"
.br
.ti -1c
.RI "static const double \fBQ2\fP = 1\&.58730158725481460165e\-03"
.br
.ti -1c
.RI "static const double \fBQ3\fP = \-7\&.93650757867487942473e\-05"
.br
.ti -1c
.RI "static const double \fBQ4\fP = 4\&.00821782732936239552e\-06"
.br
.ti -1c
.RI "static const double \fBQ5\fP = \-2\&.01099218183624371326e\-07"
.br
.in -1c
.SH "Function Documentation"
.PP
.SS "double expm1 (double x)"
.PP
Definition at line 156 of file expm1\&.c\&.
.PP
References huge, invln2, ln2_hi, ln2_lo, o_threshold, one, Q1, Q2, Q3, Q4, Q5, and tiny\&.
.PP
Referenced by cosh(), sinh(), and tanh()\&.
.PP
.nf
157 {
158 double y,hi,lo,c,t,e,hxs,hfx,r1;
159 sword k,xsb;
160 uword hx;
161
162 c = 0\&.0;
163
164 GET_HIGH_WORD(hx,x); /* high word of x */
165 xsb = hx&0x80000000; /* sign bit of x */
166 if(xsb==0) y=x;
167 else y= -x; /* y = |x| */
168 hx &= 0x7fffffff; /* high word of |x| */
169
170 /* filter out huge and non-finite argument */
171 if(hx >= 0x4043687A) { /* if |x|>=56*ln2 */
172 if(hx >= 0x40862E42) { /* if |x|>=709\&.78\&.\&.\&. */
173 if(hx>=0x7ff00000) {
174 uword low;
175 GET_LOW_WORD(low,x);
176 if(((hx&0xfffff)|low)!=0)
177 return x+x; /* NaN */
178 else return (xsb==0)? x:-1\&.0;/* exp(+-inf)={inf,-1} */
179 }
180 if(x > o_threshold) return huge*huge; /* overflow */
181 }
182 if(xsb!=0) { /* x < -56*ln2, return -1\&.0 with inexact */
183 if(x+tiny<0\&.0) /* raise inexact */
184 return tiny-one; /* return -1 */
185 }
186 }
187
188 /* argument reduction */
189 if(hx > 0x3fd62e42) { /* if |x| > 0\&.5 ln2 */
190 if(hx < 0x3FF0A2B2) { /* and |x| < 1\&.5 ln2 */
191 if(xsb==0)
192 {
193 hi = x - ln2_hi;
194 lo = ln2_lo;
195 k = 1;
196 }
197 else
198 {
199 hi = x + ln2_hi;
200 lo = -ln2_lo;
201 k = -1;
202 }
203 } else {
204 k = (sword)(invln2*x+((xsb==0)?0\&.5:-0\&.5));
205 t = k;
206 hi = x - t*ln2_hi; /* t*ln2_hi is exact here */
207 lo = t*ln2_lo;
208 }
209 x = hi - lo;
210 c = (hi-x)-lo;
211 }
212 else if(hx < 0x3c900000) { /* when |x|<2**-54, return x */
213 t = huge+x; /* return x with inexact flags when x!=0 */
214 return x - (t-(huge+x));
215 }
216 else k = 0;
217
218 /* x is now in primary range */
219 hfx = 0\&.5*x;
220 hxs = x*hfx;
221 r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5))));
222 t = 3\&.0-r1*hfx;
223 e = hxs*((r1-t)/(6\&.0 - x*t));
224 if(k==0) return x - (x*e-hxs); /* c is 0 */
225 else {
226 e = (x*(e-c)-c);
227 e -= hxs;
228 if(k== -1) return 0\&.5*(x-e)-0\&.5;
229 if(k==1) {
230 if(x < -0\&.25) return -2\&.0*(e-(x+0\&.5));
231 else return one+2\&.0*(x-e);
232 }
233 if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */
234 uword hy;
235
236 y = one-(e-x);
237 GET_HIGH_WORD(hy,y);
238 SET_HIGH_WORD(y, hy + (k<<20)); /* add k to y's exponent */
239 return y-one;
240 }
241 t = one;
242 if(k<20) {
243 uword hy;
244
245 SET_HIGH_WORD(t, 0x3ff00000 - (0x200000>>k)); /* t=1-2^-k */
246 y = t-(e-x);
247 GET_HIGH_WORD(hy, y);
248 SET_HIGH_WORD(y, hy + (k<<20)); /* add k to y's exponent */
249 } else {
250 uword hy;
251
252 SET_HIGH_WORD(t, (0x3ff-k)<<20); /* 2^-k */
253 y = x-(e+t);
254 y += one;
255 GET_HIGH_WORD(hy, y);
256 SET_HIGH_WORD(y, hy + (k<<20)); /* add k to y's exponent */
257 }
258 }
259 return y;
260 }
.fi
.SH "Variable Documentation"
.PP
.SS "const double huge = 1\&.0e+300\fC [static]\fP"
.PP
Definition at line 143 of file expm1\&.c\&.
.PP
Referenced by expm1()\&.
.SS "const double invln2 = 1\&.44269504088896338700e+00\fC [static]\fP"
.PP
Definition at line 148 of file expm1\&.c\&.
.PP
Referenced by expm1()\&.
.SS "const double ln2_hi = 6\&.93147180369123816490e\-01\fC [static]\fP"
.PP
Definition at line 146 of file expm1\&.c\&.
.PP
Referenced by expm1()\&.
.SS "const double ln2_lo = 1\&.90821492927058770002e\-10\fC [static]\fP"
.PP
Definition at line 147 of file expm1\&.c\&.
.PP
Referenced by expm1()\&.
.SS "const double o_threshold = 7\&.09782712893383973096e+02\fC [static]\fP"
.PP
Definition at line 145 of file expm1\&.c\&.
.PP
Referenced by expm1()\&.
.SS "const double one = 1\&.0\fC [static]\fP"
.PP
Definition at line 142 of file expm1\&.c\&.
.PP
Referenced by expm1()\&.
.SS "const double Q1 = \-3\&.33333333333331316428e\-02\fC [static]\fP"
.PP
Definition at line 150 of file expm1\&.c\&.
.PP
Referenced by expm1()\&.
.SS "const double Q2 = 1\&.58730158725481460165e\-03\fC [static]\fP"
.PP
Definition at line 151 of file expm1\&.c\&.
.PP
Referenced by expm1()\&.
.SS "const double Q3 = \-7\&.93650757867487942473e\-05\fC [static]\fP"
.PP
Definition at line 152 of file expm1\&.c\&.
.PP
Referenced by expm1()\&.
.SS "const double Q4 = 4\&.00821782732936239552e\-06\fC [static]\fP"
.PP
Definition at line 153 of file expm1\&.c\&.
.PP
Referenced by expm1()\&.
.SS "const double Q5 = \-2\&.01099218183624371326e\-07\fC [static]\fP"
.PP
Definition at line 154 of file expm1\&.c\&.
.PP
Referenced by expm1()\&.
.SS "const double tiny = 1\&.0e\-300\fC [static]\fP"
.PP
Definition at line 144 of file expm1\&.c\&.
.PP
Referenced by expm1()\&.
.SH "Author"
.PP
Generated automatically by Doxygen for amath from the source code\&.