OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libm/] [math/] [ef_exp.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
/* ef_exp.c -- float version of e_exp.c.
2
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3
 */
4
 
5
/*
6
 * ====================================================
7
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8
 *
9
 * Developed at SunPro, 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
#include "fdlibm.h"
17
 
18
#ifdef __v810__
19
#define const
20
#endif
21
 
22
#ifdef __STDC__
23
static const float
24
#else
25
static float
26
#endif
27
one     = 1.0,
28
halF[2] = {0.5,-0.5,},
29
huge    = 1.0e+30,
30
twom100 = 7.8886090522e-31,      /* 2**-100=0x0d800000 */
31
o_threshold=  8.8721679688e+01,  /* 0x42b17180 */
32
u_threshold= -1.0397208405e+02,  /* 0xc2cff1b5 */
33
ln2HI[2]   ={ 6.9313812256e-01,         /* 0x3f317180 */
34
             -6.9313812256e-01,},       /* 0xbf317180 */
35
ln2LO[2]   ={ 9.0580006145e-06,         /* 0x3717f7d1 */
36
             -9.0580006145e-06,},       /* 0xb717f7d1 */
37
invln2 =  1.4426950216e+00,             /* 0x3fb8aa3b */
38
P1   =  1.6666667163e-01, /* 0x3e2aaaab */
39
P2   = -2.7777778450e-03, /* 0xbb360b61 */
40
P3   =  6.6137559770e-05, /* 0x388ab355 */
41
P4   = -1.6533901999e-06, /* 0xb5ddea0e */
42
P5   =  4.1381369442e-08; /* 0x3331bb4c */
43
 
44
#ifdef __STDC__
45
        float __ieee754_expf(float x)   /* default IEEE double exp */
46
#else
47
        float __ieee754_expf(x) /* default IEEE double exp */
48
        float x;
49
#endif
50
{
51
        float y,hi,lo,c,t;
52
        __int32_t k,xsb;
53
        __uint32_t hx;
54
 
55
        GET_FLOAT_WORD(hx,x);
56
        xsb = (hx>>31)&1;               /* sign bit of x */
57
        hx &= 0x7fffffff;               /* high word of |x| */
58
 
59
    /* filter out non-finite argument */
60
        if(hx >= 0x42b17218) {                  /* if |x|>=88.721... */
61
            if(hx>0x7f800000)
62
                 return x+x;                    /* NaN */
63
            if(hx==0x7f800000)
64
                return (xsb==0)? x:0.0;          /* exp(+-inf)={inf,0} */
65
            if(x > o_threshold) return huge*huge; /* overflow */
66
            if(x < u_threshold) return twom100*twom100; /* underflow */
67
        }
68
 
69
    /* argument reduction */
70
        if(hx > 0x3eb17218) {           /* if  |x| > 0.5 ln2 */
71
            if(hx < 0x3F851592) {       /* and |x| < 1.5 ln2 */
72
                hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;
73
            } else {
74
                k  = invln2*x+halF[xsb];
75
                t  = k;
76
                hi = x - t*ln2HI[0];     /* t*ln2HI is exact here */
77
                lo = t*ln2LO[0];
78
            }
79
            x  = hi - lo;
80
        }
81
        else if(hx < 0x31800000)  {     /* when |x|<2**-28 */
82
            if(huge+x>one) return one+x;/* trigger inexact */
83
        }
84
        else k = 0;
85
 
86
    /* x is now in primary range */
87
        t  = x*x;
88
        c  = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
89
        if(k==0)         return one-((x*c)/(c-(float)2.0)-x);
90
        else            y = one-((lo-(x*c)/((float)2.0-c))-hi);
91
        if(k >= -125) {
92
            __uint32_t hy;
93
            GET_FLOAT_WORD(hy,y);
94
            SET_FLOAT_WORD(y,hy+(k<<23));       /* add k to y's exponent */
95
            return y;
96
        } else {
97
            __uint32_t hy;
98
            GET_FLOAT_WORD(hy,y);
99
            SET_FLOAT_WORD(y,hy+((k+100)<<23)); /* add k to y's exponent */
100
            return y*twom100;
101
        }
102
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.