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