NCBI C++ Toolkit Cross Reference

C++/src/util/miscmath.c


  1 /*  $Id: miscmath.c 99676 2007-03-05 20:41:55Z kazimird $
  2 * ===========================================================================
  3 *
  4 * Much of this code comes from the freely distributable math library
  5 * fdlibm, for which the following notice applies:
  6 *
  7 * Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved.
  8 *
  9 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 10 * Permission to use, copy, modify, and distribute this
 11 * software is freely granted, provided that this notice 
 12 * is preserved.
 13 *
 14 * ===========================================================================
 15 *
 16 * Author (editor, really):  Aaron Ucko, NCBI
 17 *
 18 * File Description:
 19 *   Miscellaneous math functions that might not be part of the
 20 *   system's standard libraries.
 21 *
 22 * ===========================================================================
 23 */
 24 
 25 #include <ncbiconf.h>
 26 #include <util/miscmath.h>
 27 
 28 #include <math.h>
 29 
 30 #ifndef HAVE_ERF
 31 #define NEED_EXP
 32 #endif
 33 
 34 #ifdef WORDS_BIGENDIAN
 35 #define __HI(x) *(int*)&x
 36 #define __LO(x) *(1+(int*)&x)
 37 #define __HIp(x) *(int*)x
 38 #define __LOp(x) *(1+(int*)x)
 39 #else
 40 #define __HI(x) *(1+(int*)&x)
 41 #define __LO(x) *(int*)&x
 42 #define __HIp(x) *(1+(int*)x)
 43 #define __LOp(x) *(int*)x
 44 #endif
 45 
 46 #ifdef NEED_EXP
 47 /* s_IEEE754_Exp(x)
 48  * Returns the exponential of x.
 49  *
 50  * Method
 51  *   1. Argument reduction:
 52  *      Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658.
 53  *      Given x, find r and integer k such that
 54  *
 55  *               x = k*ln2 + r,  |r| <= 0.5*ln2.  
 56  *
 57  *      Here r will be represented as r = hi-lo for better 
 58  *      accuracy.
 59  *
 60  *   2. Approximation of exp(r) by a special rational function on
 61  *      the interval [0,0.34658]:
 62  *      Write
 63  *          R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ...
 64  *      We use a special Remes algorithm on [0,0.34658] to generate 
 65  *      a polynomial of degree 5 to approximate R. The maximum error 
 66  *      of this polynomial approximation is bounded by 2**-59. In
 67  *      other words,
 68  *          R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5
 69  *      (where z=r*r, and the values of P1 to P5 are listed below)
 70  *      and
 71  *          |                  5          |     -59
 72  *          | 2.0+P1*z+...+P5*z   -  R(z) | <= 2 
 73  *          |                             |
 74  *      The computation of exp(r) thus becomes
 75  *                             2*r
 76  *              exp(r) = 1 + -------
 77  *                            R - r
 78  *                                 r*R1(r)      
 79  *                     = 1 + r + ----------- (for better accuracy)
 80  *                                2 - R1(r)
 81  *      where
 82  *                               2       4             10
 83  *              R1(r) = r - (P1*r  + P2*r  + ... + P5*r   ).
 84  *      
 85  *   3. Scale back to obtain exp(x):
 86  *      From step 1, we have
 87  *         exp(x) = 2^k * exp(r)
 88  *
 89  * Special cases:
 90  *      exp(INF) is INF, exp(NaN) is NaN;
 91  *      exp(-INF) is 0, and
 92  *      for finite argument, only exp(0)=1 is exact.
 93  *
 94  * Accuracy:
 95  *      according to an error analysis, the error is always less than
 96  *      1 ulp (unit in the last place).
 97  *
 98  * Misc. info.
 99  *      For IEEE double 
100  *          if x >  7.09782712893383973096e+02 then exp(x) overflow
101  *          if x < -7.45133219101941108420e+02 then exp(x) underflow
102  *
103  * Constants:
104  * The hexadecimal values are the intended ones for the following 
105  * constants. The decimal values may be used, provided that the 
106  * compiler will convert from decimal to binary accurately enough
107  * to produce the hexadecimal values shown.
108  */
109 
110 static const double
111 one     = 1.0,
112 halF[2] = {0.5,-0.5,},
113 huge    = 1.0e+300,
114 twom1000= 9.33263618503218878990e-302,     /* 2**-1000=0x01700000,0*/
115 o_threshold=  7.09782712893383973096e+02,  /* 0x40862E42, 0xFEFA39EF */
116 u_threshold= -7.45133219101941108420e+02,  /* 0xc0874910, 0xD52D3051 */
117 ln2HI[2]   ={ 6.93147180369123816490e-01,  /* 0x3fe62e42, 0xfee00000 */
118              -6.93147180369123816490e-01,},/* 0xbfe62e42, 0xfee00000 */
119 ln2LO[2]   ={ 1.90821492927058770002e-10,  /* 0x3dea39ef, 0x35793c76 */
120              -1.90821492927058770002e-10,},/* 0xbdea39ef, 0x35793c76 */
121 invln2 =  1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */
122 P1   =  1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
123 P2   = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
124 P3   =  6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
125 P4   = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
126 P5   =  4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
127 
128 static double s_IEEE754_Exp(double x)   /* default IEEE double exp */
129 {
130         double y,hi,lo,c,t;
131         int k,xsb;
132         unsigned hx;
133 
134         hx  = __HI(x);  /* high word of x */
135         xsb = (hx>>31)&1;               /* sign bit of x */
136         hx &= 0x7fffffff;               /* high word of |x| */
137 
138     /* filter out non-finite argument */
139         if(hx >= 0x40862E42) {                  /* if |x|>=709.78... */
140             if(hx>=0x7ff00000) {
141                 if(((hx&0xfffff)|__LO(x))!=0) 
142                      return x+x;                /* NaN */
143                 else return (xsb==0)? x:0.0;    /* exp(+-inf)={inf,0} */
144             }
145             if(x > o_threshold)
146                 return huge*huge; /* NCBI_FAKE_WARNING [deliberate overflow] */
147             if(x < u_threshold) return twom1000*twom1000; /* underflow */
148         }
149 
150     /* argument reduction */
151         if(hx > 0x3fd62e42) {           /* if  |x| > 0.5 ln2 */ 
152             if(hx < 0x3FF0A2B2) {       /* and |x| < 1.5 ln2 */
153                 hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;
154             } else {
155                 k  = (int)(invln2*x+halF[xsb]);
156                 t  = k;
157                 hi = x - t*ln2HI[0];    /* t*ln2HI is exact here */
158                 lo = t*ln2LO[0];
159             }
160             x  = hi - lo;
161         } 
162         else if(hx < 0x3e300000)  {     /* when |x|<2**-28 */
163             if(huge+x>one) return one+x;/* trigger inexact */
164         }
165         else k = 0;
166 
167     /* x is now in primary range */
168         t  = x*x;
169         c  = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
170         if(k==0)        return one-((x*c)/(c-2.0)-x); 
171         else            y = one-((lo-(x*c)/(2.0-c))-hi);
172         if(k >= -1021) {
173             __HI(y) += (k<<20); /* add k to y's exponent */
174             return y;
175         } else {
176             __HI(y) += ((k+1000)<<20);/* add k to y's exponent */
177             return y*twom1000;
178         }
179 }
180 #endif
181 
182 /* double erf(double x)
183  * double erfc(double x)
184  *                           x
185  *                    2      |\
186  *     erf(x)  =  ---------  | exp(-t*t)dt
187  *                 sqrt(pi) \| 
188  *                           0
189  *
190  *     erfc(x) =  1-erf(x)
191  *  Note that 
192  *              erf(-x) = -erf(x)
193  *              erfc(-x) = 2 - erfc(x)
194  *
195  * Method:
196  *      1. For |x| in [0, 0.84375]
197  *          erf(x)  = x + x*R(x^2)
198  *          erfc(x) = 1 - erf(x)           if x in [-.84375,0.25]
199  *                  = 0.5 + ((0.5-x)-x*R)  if x in [0.25,0.84375]
200  *         where R = P/Q where P is an odd poly of degree 8 and
201  *         Q is an odd poly of degree 10.
202  *                                               -57.90
203  *                      | R - (erf(x)-x)/x | <= 2
204  *      
205  *
206  *         Remark. The formula is derived by noting
207  *          erf(x) = (2/sqrt(pi))*(x - x^3/3 + x^5/10 - x^7/42 + ....)
208  *         and that
209  *          2/sqrt(pi) = 1.128379167095512573896158903121545171688
210  *         is close to one. The interval is chosen because the fix
211  *         point of erf(x) is near 0.6174 (i.e., erf(x)=x when x is
212  *         near 0.6174), and by some experiment, 0.84375 is chosen to
213  *         guarantee the error is less than one ulp for erf.
214  *
215  *      2. For |x| in [0.84375,1.25], let s = |x| - 1, and
216  *         c = 0.84506291151 rounded to single (24 bits)
217  *              erf(x)  = sign(x) * (c  + P1(s)/Q1(s))
218  *              erfc(x) = (1-c)  - P1(s)/Q1(s) if x > 0
219  *                        1+(c+P1(s)/Q1(s))    if x < 0
220  *              |P1/Q1 - (erf(|x|)-c)| <= 2**-59.06
221  *         Remark: here we use the taylor series expansion at x=1.
222  *              erf(1+s) = erf(1) + s*Poly(s)
223  *                       = 0.845.. + P1(s)/Q1(s)
224  *         That is, we use rational approximation to approximate
225  *                      erf(1+s) - (c = (single)0.84506291151)
226  *         Note that |P1/Q1|< 0.078 for x in [0.84375,1.25]
227  *         where 
228  *              P1(s) = degree 6 poly in s
229  *              Q1(s) = degree 6 poly in s
230  *
231  *      3. For x in [1.25,1/0.35(~2.857143)], 
232  *              erfc(x) = (1/x)*exp(-x*x-0.5625+R1/S1)
233  *              erf(x)  = 1 - erfc(x)
234  *         where 
235  *              R1(z) = degree 7 poly in z, (z=1/x^2)
236  *              S1(z) = degree 8 poly in z
237  *
238  *      4. For x in [1/0.35,28]
239  *              erfc(x) = (1/x)*exp(-x*x-0.5625+R2/S2) if x > 0
240  *                      = 2.0 - (1/x)*exp(-x*x-0.5625+R2/S2) if -6<x<0
241  *                      = 2.0 - tiny            (if x <= -6)
242  *              erf(x)  = sign(x)*(1.0 - erfc(x)) if x < 6, else
243  *              erf(x)  = sign(x)*(1.0 - tiny)
244  *         where
245  *              R2(z) = degree 6 poly in z, (z=1/x^2)
246  *              S2(z) = degree 7 poly in z
247  *
248  *      Note1:
249  *         To compute exp(-x*x-0.5625+R/S), let s be a single
250  *         precision number and s := x; then
251  *              -x*x = -s*s + (s-x)*(s+x)
252  *              exp(-x*x-0.5626+R/S) = 
253  *                      exp(-s*s-0.5625)*exp((s-x)*(s+x)+R/S);
254  *      Note2:
255  *         Here 4 and 5 make use of the asymptotic series
256  *                        exp(-x*x)
257  *              erfc(x) ~ ---------- * ( 1 + Poly(1/x^2) )
258  *                        x*sqrt(pi)
259  *         We use rational approximation to approximate
260  *              g(s)=f(1/x^2) = log(erfc(x)*x) - x*x + 0.5625
261  *         Here is the error bound for R1/S1 and R2/S2
262  *              |R1/S1 - f(x)|  < 2**(-62.57)
263  *              |R2/S2 - f(x)|  < 2**(-61.52)
264  *
265  *      5. For inf > x >= 28
266  *              erf(x)  = sign(x) *(1 - tiny)  (raise inexact)
267  *              erfc(x) = tiny*tiny (raise underflow) if x > 0
268  *                      = 2 - tiny if x<0
269  *
270  *      7. Special case:
271  *              erf(0)  = 0, erf(inf)  = 1, erf(-inf) = -1,
272  *              erfc(0) = 1, erfc(inf) = 0, erfc(-inf) = 2, 
273  *              erfc/erf(NaN) is NaN
274  */
275 
276 #ifndef HAVE_ERF
277 static const double
278 tiny        = 1e-300,
279 half=  5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
280 /* one =  1.00000000000000000000e+00, */ /* 0x3FF00000, 0x00000000 */
281 two =  2.00000000000000000000e+00, /* 0x40000000, 0x00000000 */
282         /* c = (float)0.84506291151 */
283 erx =  8.45062911510467529297e-01, /* 0x3FEB0AC1, 0x60000000 */
284 /*
285  * Coefficients for approximation to  erf on [0,0.84375]
286  */
287 efx =  1.28379167095512586316e-01, /* 0x3FC06EBA, 0x8214DB69 */
288 efx8=  1.02703333676410069053e+00, /* 0x3FF06EBA, 0x8214DB69 */
289 pp0  =  1.28379167095512558561e-01, /* 0x3FC06EBA, 0x8214DB68 */
290 pp1  = -3.25042107247001499370e-01, /* 0xBFD4CD7D, 0x691CB913 */
291 pp2  = -2.84817495755985104766e-02, /* 0xBF9D2A51, 0xDBD7194F */
292 pp3  = -5.77027029648944159157e-03, /* 0xBF77A291, 0x236668E4 */
293 pp4  = -2.37630166566501626084e-05, /* 0xBEF8EAD6, 0x120016AC */
294 qq1  =  3.97917223959155352819e-01, /* 0x3FD97779, 0xCDDADC09 */
295 qq2  =  6.50222499887672944485e-02, /* 0x3FB0A54C, 0x5536CEBA */
296 qq3  =  5.08130628187576562776e-03, /* 0x3F74D022, 0xC4D36B0F */
297 qq4  =  1.32494738004321644526e-04, /* 0x3F215DC9, 0x221C1A10 */
298 qq5  = -3.96022827877536812320e-06, /* 0xBED09C43, 0x42A26120 */
299 /*
300  * Coefficients for approximation to  erf  in [0.84375,1.25] 
301  */
302 pa0  = -2.36211856075265944077e-03, /* 0xBF6359B8, 0xBEF77538 */
303 pa1  =  4.14856118683748331666e-01, /* 0x3FDA8D00, 0xAD92B34D */
304 pa2  = -3.72207876035701323847e-01, /* 0xBFD7D240, 0xFBB8C3F1 */
305 pa3  =  3.18346619901161753674e-01, /* 0x3FD45FCA, 0x805120E4 */
306 pa4  = -1.10894694282396677476e-01, /* 0xBFBC6398, 0x3D3E28EC */
307 pa5  =  3.54783043256182359371e-02, /* 0x3FA22A36, 0x599795EB */
308 pa6  = -2.16637559486879084300e-03, /* 0xBF61BF38, 0x0A96073F */
309 qa1  =  1.06420880400844228286e-01, /* 0x3FBB3E66, 0x18EEE323 */
310 qa2  =  5.40397917702171048937e-01, /* 0x3FE14AF0, 0x92EB6F33 */
311 qa3  =  7.18286544141962662868e-02, /* 0x3FB2635C, 0xD99FE9A7 */
312 qa4  =  1.26171219808761642112e-01, /* 0x3FC02660, 0xE763351F */
313 qa5  =  1.36370839120290507362e-02, /* 0x3F8BEDC2, 0x6B51DD1C */
314 qa6  =  1.19844998467991074170e-02, /* 0x3F888B54, 0x5735151D */
315 /*
316  * Coefficients for approximation to  erfc in [1.25,1/0.35]
317  */
318 ra0  = -9.86494403484714822705e-03, /* 0xBF843412, 0x600D6435 */
319 ra1  = -6.93858572707181764372e-01, /* 0xBFE63416, 0xE4BA7360 */
320 ra2  = -1.05586262253232909814e+01, /* 0xC0251E04, 0x41B0E726 */
321 ra3  = -6.23753324503260060396e+01, /* 0xC04F300A, 0xE4CBA38D */
322 ra4  = -1.62396669462573470355e+02, /* 0xC0644CB1, 0x84282266 */
323 ra5  = -1.84605092906711035994e+02, /* 0xC067135C, 0xEBCCABB2 */
324 ra6  = -8.12874355063065934246e+01, /* 0xC0545265, 0x57E4D2F2 */
325 ra7  = -9.81432934416914548592e+00, /* 0xC023A0EF, 0xC69AC25C */
326 sa1  =  1.96512716674392571292e+01, /* 0x4033A6B9, 0xBD707687 */
327 sa2  =  1.37657754143519042600e+02, /* 0x4061350C, 0x526AE721 */
328 sa3  =  4.34565877475229228821e+02, /* 0x407B290D, 0xD58A1A71 */
329 sa4  =  6.45387271733267880336e+02, /* 0x40842B19, 0x21EC2868 */
330 sa5  =  4.29008140027567833386e+02, /* 0x407AD021, 0x57700314 */
331 sa6  =  1.08635005541779435134e+02, /* 0x405B28A3, 0xEE48AE2C */
332 sa7  =  6.57024977031928170135e+00, /* 0x401A47EF, 0x8E484A93 */
333 sa8  = -6.04244152148580987438e-02, /* 0xBFAEEFF2, 0xEE749A62 */
334 /*
335  * Coefficients for approximation to  erfc in [1/.35,28]
336  */
337 rb0  = -9.86494292470009928597e-03, /* 0xBF843412, 0x39E86F4A */
338 rb1  = -7.99283237680523006574e-01, /* 0xBFE993BA, 0x70C285DE */
339 rb2  = -1.77579549177547519889e+01, /* 0xC031C209, 0x555F995A */
340 rb3  = -1.60636384855821916062e+02, /* 0xC064145D, 0x43C5ED98 */
341 rb4  = -6.37566443368389627722e+02, /* 0xC083EC88, 0x1375F228 */
342 rb5  = -1.02509513161107724954e+03, /* 0xC0900461, 0x6A2E5992 */
343 rb6  = -4.83519191608651397019e+02, /* 0xC07E384E, 0x9BDC383F */
344 sb1  =  3.03380607434824582924e+01, /* 0x403E568B, 0x261D5190 */
345 sb2  =  3.25792512996573918826e+02, /* 0x40745CAE, 0x221B9F0A */
346 sb3  =  1.53672958608443695994e+03, /* 0x409802EB, 0x189D5118 */
347 sb4  =  3.19985821950859553908e+03, /* 0x40A8FFB7, 0x688C246A */
348 sb5  =  2.55305040643316442583e+03, /* 0x40A3F219, 0xCEDF3BE6 */
349 sb6  =  4.74528541206955367215e+02, /* 0x407DA874, 0xE79FE763 */
350 sb7  = -2.24409524465858183362e+01; /* 0xC03670E2, 0x42712D62 */
351 #endif
352 
353 double NCBI_Erf(double x)
354 {
355 #ifdef HAVE_ERF
356     return erf(x);
357 #else
358         int hx,ix,i;
359         double R,S,P,Q,s,y,z,r;
360         hx = __HI(x);
361         ix = hx&0x7fffffff;
362         if(ix>=0x7ff00000) {            /* erf(nan)=nan */
363             i = ((unsigned)hx>>31)<<1;
364             return (double)(1-i)+one/x; /* erf(+-inf)=+-1 */
365         }
366 
367         if(ix < 0x3feb0000) {           /* |x|<0.84375 */
368             if(ix < 0x3e300000) {       /* |x|<2**-28 */
369                 if (ix < 0x00800000) 
370                     return 0.125*(8.0*x+efx8*x);  /*avoid underflow */
371                 return x + efx*x;
372             }
373             z = x*x;
374             r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
375             s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
376             y = r/s;
377             return x + x*y;
378         }
379         if(ix < 0x3ff40000) {           /* 0.84375 <= |x| < 1.25 */
380             s = fabs(x)-one;
381             P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
382             Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
383             if(hx>=0) return erx + P/Q; else return -erx - P/Q;
384         }
385         if (ix >= 0x40180000) {         /* inf>|x|>=6 */
386             if(hx>=0) return one-tiny; else return tiny-one;
387         }
388         x = fabs(x);
389         s = one/(x*x);
390         if(ix< 0x4006DB6E) {    /* |x| < 1/0.35 */
391             R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
392                                 ra5+s*(ra6+s*ra7))))));
393             S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
394                                 sa5+s*(sa6+s*(sa7+s*sa8)))))));
395         } else {        /* |x| >= 1/0.35 */
396             R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
397                                 rb5+s*rb6)))));
398             S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
399                                 sb5+s*(sb6+s*sb7))))));
400         }
401         z  = x;  
402         __LO(z) = 0;
403         r  =  s_IEEE754_Exp(-z*z-0.5625)*s_IEEE754_Exp((z-x)*(z+x)+R/S);
404         if(hx>=0) return one-r/x; else return  r/x-one;
405 #endif
406 }
407 
408 double NCBI_ErfC(double x)
409 {
410 #ifdef HAVE_ERF
411     return erfc(x);
412 #else
413         int hx,ix;
414         double R,S,P,Q,s,y,z,r;
415         hx = __HI(x);
416         ix = hx&0x7fffffff;
417         if(ix>=0x7ff00000) {                    /* erfc(nan)=nan */
418                                                 /* erfc(+-inf)=0,2 */
419             return (double)(((unsigned)hx>>31)<<1)+one/x;
420         }
421 
422         if(ix < 0x3feb0000) {           /* |x|<0.84375 */
423             if(ix < 0x3c700000)         /* |x|<2**-56 */
424                 return one-x;
425             z = x*x;
426             r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
427             s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
428             y = r/s;
429             if(hx < 0x3fd00000) {       /* x<1/4 */
430                 return one-(x+x*y);
431             } else {
432                 r = x*y;
433                 r += (x-half);
434                 return half - r ;
435             }
436         }
437         if(ix < 0x3ff40000) {           /* 0.84375 <= |x| < 1.25 */
438             s = fabs(x)-one;
439             P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
440             Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
441             if(hx>=0) {
442                 z  = one-erx; return z - P/Q; 
443             } else {
444                 z = erx+P/Q; return one+z;
445             }
446         }
447         if (ix < 0x403c0000) {          /* |x|<28 */
448             x = fabs(x);
449             s = one/(x*x);
450             if(ix< 0x4006DB6D) {        /* |x| < 1/.35 ~ 2.857143*/
451                 R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
452                                 ra5+s*(ra6+s*ra7))))));
453                 S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
454                                 sa5+s*(sa6+s*(sa7+s*sa8)))))));
455             } else {                    /* |x| >= 1/.35 ~ 2.857143 */
456                 if(hx<0&&ix>=0x40180000) return two-tiny;/* x < -6 */
457                 R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
458                                 rb5+s*rb6)))));
459                 S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
460                                 sb5+s*(sb6+s*sb7))))));
461             }
462             z  = x;
463             __LO(z)  = 0;
464             r  =  s_IEEE754_Exp(-z*z-0.5625)*
465                         s_IEEE754_Exp((z-x)*(z+x)+R/S);
466             if(hx>0) return r/x; else return two-r/x;
467         } else {
468             if(hx>0) return tiny*tiny; else return two-tiny;
469         }
470 #endif
471 }
472 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.