source: trunk/libs/newlib/src/newlib/libm/math/w_exp.c @ 567

Last change on this file since 567 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.7 KB
Line 
1
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/*
15FUNCTION
16        <<exp>>, <<expf>>---exponential
17INDEX
18        exp
19INDEX
20        expf
21
22SYNOPSIS
23        #include <math.h>
24        double exp(double <[x]>);
25        float expf(float <[x]>);
26
27DESCRIPTION
28        <<exp>> and <<expf>> calculate the exponential of <[x]>, that is,
29        @ifnottex
30        e raised to the power <[x]> (where e
31        @end ifnottex
32        @tex
33        $e^x$ (where $e$
34        @end tex
35        is the base of the natural system of logarithms, approximately 2.71828).
36
37        You can use the (non-ANSI) function <<matherr>> to specify
38        error handling for these functions.
39
40RETURNS
41        On success, <<exp>> and <<expf>> return the calculated value.
42        If the result underflows, the returned value is <<0>>.  If the
43        result overflows, the returned value is <<HUGE_VAL>>.  In
44        either case, <<errno>> is set to <<ERANGE>>.
45
46PORTABILITY
47        <<exp>> is ANSI C.  <<expf>> is an extension.
48
49*/
50
51/*
52 * wrapper exp(x)
53 */
54
55#include "fdlibm.h"
56#include <errno.h>
57
58#ifndef _DOUBLE_IS_32BITS
59
60#ifdef __STDC__
61static const double
62#else
63static double
64#endif
65o_threshold=  7.09782712893383973096e+02,  /* 0x40862E42, 0xFEFA39EF */
66u_threshold= -7.45133219101941108420e+02;  /* 0xc0874910, 0xD52D3051 */
67
68#ifdef __STDC__
69        double exp(double x)            /* wrapper exp */
70#else
71        double exp(x)                   /* wrapper exp */
72        double x;
73#endif
74{
75#ifdef _IEEE_LIBM
76        return __ieee754_exp(x);
77#else
78        double z;
79        struct exception exc;
80        z = __ieee754_exp(x);
81        if(_LIB_VERSION == _IEEE_) return z;
82        if(finite(x)) {
83            if(x>o_threshold) {
84                /* exp(finite) overflow */
85#ifndef HUGE_VAL
86#define HUGE_VAL inf
87                double inf = 0.0;
88
89                SET_HIGH_WORD(inf,0x7ff00000);  /* set inf to infinite */
90#endif
91                exc.type = OVERFLOW;
92                exc.name = "exp";
93                exc.err = 0;
94                exc.arg1 = exc.arg2 = x;
95                if (_LIB_VERSION == _SVID_)
96                  exc.retval = HUGE;
97                else
98                  exc.retval = HUGE_VAL;
99                if (_LIB_VERSION == _POSIX_)
100                  errno = ERANGE;
101                else if (!matherr(&exc)) {
102                        errno = ERANGE;
103                }
104                if (exc.err != 0)
105                   errno = exc.err;
106                return exc.retval; 
107            } else if(x<u_threshold) {
108                /* exp(finite) underflow */
109                exc.type = UNDERFLOW;
110                exc.name = "exp";
111                exc.err = 0;
112                exc.arg1 = exc.arg2 = x;
113                exc.retval = 0.0;
114                if (_LIB_VERSION == _POSIX_)
115                  errno = ERANGE;
116                else if (!matherr(&exc)) {
117                        errno = ERANGE;
118                }
119                if (exc.err != 0)
120                   errno = exc.err;
121                return exc.retval; 
122            } 
123        } 
124        return z;
125#endif
126}
127
128#endif /* defined(_DOUBLE_IS_32BITS) */
Note: See TracBrowser for help on using the repository browser.