Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / native / fdlibm / w_exp.c
blob45e087b45f9e42b9b82e0c62cfc5afad55a9cf66
2 /* @(#)w_exp.c 5.1 93/09/24 */
3 /*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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 * ====================================================
15 FUNCTION
16 <<exp>>, <<expf>>---exponential
17 INDEX
18 exp
19 INDEX
20 expf
22 ANSI_SYNOPSIS
23 #include <math.h>
24 double exp(double <[x]>);
25 float expf(float <[x]>);
27 TRAD_SYNOPSIS
28 #include <math.h>
29 double exp(<[x]>);
30 double <[x]>;
32 float expf(<[x]>);
33 float <[x]>;
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).
45 You can use the (non-ANSI) function <<matherr>> to specify
46 error handling for these functions.
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>>.
54 PORTABILITY
55 <<exp>> is ANSI C. <<expf>> is an extension.
59 /*
60 * wrapper exp(x)
63 #include "fdlibm.h"
64 #include <errno.h>
66 #ifndef _DOUBLE_IS_32BITS
68 #ifndef _IEEE_LIBM
70 #ifdef __STDC__
71 static const double
72 #else
73 static double
74 #endif
75 o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */
76 u_threshold= -7.45133219101941108420e+02; /* 0xc0874910, 0xD52D3051 */
78 #endif
80 #ifdef __STDC__
81 double exp(double x) /* wrapper exp */
82 #else
83 double exp(x) /* wrapper exp */
84 double x;
85 #endif
87 #ifdef _IEEE_LIBM
88 return __ieee754_exp(x);
89 #else
90 double z;
91 struct exception exc;
92 z = __ieee754_exp(x);
93 if(_LIB_VERSION == _IEEE_) return z;
94 if(finite(x)) {
95 if(x>o_threshold) {
96 /* exp(finite) overflow */
97 #ifndef HUGE_VAL
98 #define HUGE_VAL inf
99 double inf = 0.0;
101 SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
102 #endif
103 exc.type = OVERFLOW;
104 exc.name = "exp";
105 exc.err = 0;
106 exc.arg1 = exc.arg2 = x;
107 if (_LIB_VERSION == _SVID_)
108 exc.retval = HUGE;
109 else
110 exc.retval = HUGE_VAL;
111 if (_LIB_VERSION == _POSIX_)
112 errno = ERANGE;
113 else if (!matherr(&exc)) {
114 errno = ERANGE;
116 if (exc.err != 0)
117 errno = exc.err;
118 return exc.retval;
119 } else if(x<u_threshold) {
120 /* exp(finite) underflow */
121 exc.type = UNDERFLOW;
122 exc.name = "exp";
123 exc.err = 0;
124 exc.arg1 = exc.arg2 = x;
125 exc.retval = 0.0;
126 if (_LIB_VERSION == _POSIX_)
127 errno = ERANGE;
128 else if (!matherr(&exc)) {
129 errno = ERANGE;
131 if (exc.err != 0)
132 errno = exc.err;
133 return exc.retval;
136 return z;
137 #endif
140 #endif /* defined(_DOUBLE_IS_32BITS) */