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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
 
2
/* @(#)w_exp.c 5.1 93/09/24 */
3
/*
4
 * ====================================================
5
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6
 *
7
 * Developed at SunPro, a Sun Microsystems, Inc. business.
8
 * Permission to use, copy, modify, and distribute this
9
 * software is freely granted, provided that this notice
10
 * is preserved.
11
 * ====================================================
12
 */
13
 
14
/*
15
FUNCTION
16
        <<exp>>, <<expf>>---exponential
17
INDEX
18
        exp
19
INDEX
20
        expf
21
 
22
ANSI_SYNOPSIS
23
        #include <math.h>
24
        double exp(double <[x]>);
25
        float expf(float <[x]>);
26
 
27
TRAD_SYNOPSIS
28
        #include <math.h>
29
        double exp(<[x]>);
30
        double <[x]>;
31
 
32
        float expf(<[x]>);
33
        float <[x]>;
34
 
35
DESCRIPTION
36
        <<exp>> and <<expf>> calculate the exponential of <[x]>, that is,
37
        @ifinfo
38
        e raised to the power <[x]> (where e
39
        @end ifinfo
40
        @tex
41
        $e^x$ (where $e$
42
        @end tex
43
        is the base of the natural system of logarithms, approximately 2.71828).
44
 
45
        You can use the (non-ANSI) function <<matherr>> to specify
46
        error handling for these functions.
47
 
48
RETURNS
49
        On success, <<exp>> and <<expf>> return the calculated value.
50
        If the result underflows, the returned value is <<0>>.  If the
51
        result overflows, the returned value is <<HUGE_VAL>>.  In
52
        either case, <<errno>> is set to <<ERANGE>>.
53
 
54
PORTABILITY
55
        <<exp>> is ANSI C.  <<expf>> is an extension.
56
 
57
*/
58
 
59
/*
60
 * wrapper exp(x)
61
 */
62
 
63
#include "fdlibm.h"
64
#include <errno.h>
65
 
66
#ifndef _DOUBLE_IS_32BITS
67
 
68
#ifdef __STDC__
69
static const double
70
#else
71
static double
72
#endif
73
o_threshold=  7.09782712893383973096e+02,  /* 0x40862E42, 0xFEFA39EF */
74
u_threshold= -7.45133219101941108420e+02;  /* 0xc0874910, 0xD52D3051 */
75
 
76
#ifdef __STDC__
77
        double exp(double x)            /* wrapper exp */
78
#else
79
        double exp(x)                   /* wrapper exp */
80
        double x;
81
#endif
82
{
83
#ifdef _IEEE_LIBM
84
        return __ieee754_exp(x);
85
#else
86
        double z;
87
        struct exception exc;
88
        z = __ieee754_exp(x);
89
        if(_LIB_VERSION == _IEEE_) return z;
90
        if(finite(x)) {
91
            if(x>o_threshold) {
92
                /* exp(finite) overflow */
93
#ifndef HUGE_VAL
94
#define HUGE_VAL inf
95
                double inf = 0.0;
96
 
97
                SET_HIGH_WORD(inf,0x7ff00000);  /* set inf to infinite */
98
#endif
99
                exc.type = OVERFLOW;
100
                exc.name = "exp";
101 56 joel
                exc.err = 0;
102
                exc.arg1 = exc.arg2 = x;
103 39 lampret
                if (_LIB_VERSION == _SVID_)
104
                  exc.retval = HUGE;
105
                else
106
                  exc.retval = HUGE_VAL;
107
                if (_LIB_VERSION == _POSIX_)
108
                  errno = ERANGE;
109
                else if (!matherr(&exc)) {
110
                        errno = ERANGE;
111
                }
112
                if (exc.err != 0)
113
                   errno = exc.err;
114
                return exc.retval;
115
            } else if(x<u_threshold) {
116
                /* exp(finite) underflow */
117
                exc.type = UNDERFLOW;
118
                exc.name = "exp";
119 56 joel
                exc.err = 0;
120
                exc.arg1 = exc.arg2 = x;
121 39 lampret
                exc.retval = 0.0;
122
                if (_LIB_VERSION == _POSIX_)
123
                  errno = ERANGE;
124
                else if (!matherr(&exc)) {
125
                        errno = ERANGE;
126
                }
127
                if (exc.err != 0)
128
                   errno = exc.err;
129
                return exc.retval;
130
            }
131
        }
132
        return z;
133
#endif
134
}
135
 
136
#endif /* defined(_DOUBLE_IS_32BITS) */

powered by: WebSVN 2.1.0

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