Rev 4872 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4349 | 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 | |||
15 | < |
||
16 | INDEX |
||
17 | pow |
||
18 | INDEX |
||
19 | powf |
||
20 | |||
21 | |||
22 | |||
23 | |||
24 | double pow(double <[x]>, double <[y]>); |
||
25 | float powf(float <[x]>, float <[y]>); |
||
26 | |||
27 | TRAD_SYNOPSIS |
||
28 | |||
29 | double pow(<[x]>, <[y]>); |
||
30 | double <[x]>, <[y]>; |
||
31 | |||
32 | float powf(<[x]>, <[y]>); |
||
33 | |||
34 | |||
35 | DESCRIPTION |
||
36 | |||
37 | @tex |
||
38 | (That is, $x^y$.) |
||
39 | @end tex |
||
40 | |||
41 | RETURNS |
||
42 | |||
43 | |||
44 | When the argument values would produce overflow, < |
||
45 | |||
46 | argument <[x]> passed to < |
||
47 | noninteger, and <[y]> is also not an integer, then < |
||
48 | is set to < |
||
49 | < |
||
50 | |||
51 | You can modify error handling for these functions using < |
||
52 | |||
53 | PORTABILITY |
||
54 | |||
55 | |||
56 | /* |
||
57 | |||
58 | */ |
||
59 | |||
60 | #include "fdlibm.h" |
||
61 | |||
62 | |||
63 | #ifndef _DOUBLE_IS_32BITS |
||
64 | |||
65 | #ifdef __STDC__ |
||
66 | |||
67 | #else |
||
68 | double pow(x,y) /* wrapper pow */ |
||
69 | double x,y; |
||
70 | #endif |
||
71 | { |
||
72 | #ifdef _IEEE_LIBM |
||
73 | return __ieee754_pow(x,y); |
||
74 | #else |
||
75 | double z; |
||
76 | #ifndef HUGE_VAL |
||
77 | #define HUGE_VAL inf |
||
78 | double inf = 0.0; |
||
79 | |||
80 | SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ |
||
81 | |||
82 | struct exception exc; |
||
83 | z=__ieee754_pow(x,y); |
||
84 | if(_LIB_VERSION == _IEEE_|| isnan(y)) return z; |
||
85 | if(isnan(x)) { |
||
86 | if(y==0.0) { |
||
87 | /* pow(NaN,0.0) */ |
||
88 | /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */ |
||
89 | exc.type = DOMAIN; |
||
90 | exc.name = "pow"; |
||
91 | exc.err = 0; |
||
92 | exc.arg1 = x; |
||
93 | exc.arg2 = y; |
||
94 | exc.retval = 1.0; |
||
95 | if (_LIB_VERSION == _IEEE_ || |
||
96 | _LIB_VERSION == _POSIX_) exc.retval = 1.0; |
||
97 | else if (!matherr(&exc)) { |
||
98 | errno = EDOM; |
||
99 | } |
||
100 | if (exc.err != 0) |
||
101 | errno = exc.err; |
||
102 | return exc.retval; |
||
103 | } else |
||
104 | return z; |
||
105 | } |
||
106 | if(x==0.0){ |
||
107 | if(y==0.0) { |
||
108 | /* pow(0.0,0.0) */ |
||
109 | /* error only if _LIB_VERSION == _SVID_ */ |
||
110 | exc.type = DOMAIN; |
||
111 | exc.name = "pow"; |
||
112 | exc.err = 0; |
||
113 | exc.arg1 = x; |
||
114 | exc.arg2 = y; |
||
115 | exc.retval = 0.0; |
||
116 | if (_LIB_VERSION != _SVID_) exc.retval = 1.0; |
||
117 | else if (!matherr(&exc)) { |
||
118 | errno = EDOM; |
||
119 | } |
||
120 | if (exc.err != 0) |
||
121 | errno = exc.err; |
||
122 | return exc.retval; |
||
123 | } |
||
124 | if(finite(y)&&y<0.0) { |
||
125 | /* 0**neg */ |
||
126 | exc.type = DOMAIN; |
||
127 | exc.name = "pow"; |
||
128 | exc.err = 0; |
||
129 | exc.arg1 = x; |
||
130 | exc.arg2 = y; |
||
131 | if (_LIB_VERSION == _SVID_) |
||
132 | exc.retval = 0.0; |
||
133 | else |
||
134 | exc.retval = -HUGE_VAL; |
||
135 | if (_LIB_VERSION == _POSIX_) |
||
136 | errno = EDOM; |
||
137 | else if (!matherr(&exc)) { |
||
138 | errno = EDOM; |
||
139 | } |
||
140 | if (exc.err != 0) |
||
141 | errno = exc.err; |
||
142 | return exc.retval; |
||
143 | } |
||
144 | return z; |
||
145 | } |
||
146 | if(!finite(z)) { |
||
147 | if(finite(x)&&finite(y)) { |
||
148 | if(isnan(z)) { |
||
149 | /* neg**non-integral */ |
||
150 | exc.type = DOMAIN; |
||
151 | exc.name = "pow"; |
||
152 | exc.err = 0; |
||
153 | exc.arg1 = x; |
||
154 | exc.arg2 = y; |
||
155 | if (_LIB_VERSION == _SVID_) |
||
156 | exc.retval = 0.0; |
||
157 | else |
||
158 | exc.retval = 0.0/0.0; /* X/Open allow NaN */ |
||
159 | if (_LIB_VERSION == _POSIX_) |
||
160 | errno = EDOM; |
||
161 | else if (!matherr(&exc)) { |
||
162 | errno = EDOM; |
||
163 | } |
||
164 | if (exc.err != 0) |
||
165 | errno = exc.err; |
||
166 | return exc.retval; |
||
167 | } else { |
||
168 | /* pow(x,y) overflow */ |
||
169 | exc.type = OVERFLOW; |
||
170 | exc.name = "pow"; |
||
171 | exc.err = 0; |
||
172 | exc.arg1 = x; |
||
173 | exc.arg2 = y; |
||
174 | if (_LIB_VERSION == _SVID_) { |
||
175 | exc.retval = HUGE; |
||
176 | y *= 0.5; |
||
177 | if(x<0.0&&rint(y)!=y) exc.retval = -HUGE; |
||
178 | } else { |
||
179 | exc.retval = HUGE_VAL; |
||
180 | y *= 0.5; |
||
181 | if(x<0.0&&rint(y)!=y) exc.retval = -HUGE_VAL; |
||
182 | } |
||
183 | if (_LIB_VERSION == _POSIX_) |
||
184 | errno = ERANGE; |
||
185 | else if (!matherr(&exc)) { |
||
186 | errno = ERANGE; |
||
187 | } |
||
188 | if (exc.err != 0) |
||
189 | errno = exc.err; |
||
190 | return exc.retval; |
||
191 | } |
||
192 | } |
||
193 | } |
||
194 | if(z==0.0&&finite(x)&&finite(y)) { |
||
195 | /* pow(x,y) underflow */ |
||
196 | exc.type = UNDERFLOW; |
||
197 | exc.name = "pow"; |
||
198 | exc.err = 0; |
||
199 | exc.arg1 = x; |
||
200 | exc.arg2 = y; |
||
201 | exc.retval = 0.0; |
||
202 | if (_LIB_VERSION == _POSIX_) |
||
203 | errno = ERANGE; |
||
204 | else if (!matherr(&exc)) { |
||
205 | errno = ERANGE; |
||
206 | } |
||
207 | if (exc.err != 0) |
||
208 | errno = exc.err; |
||
209 | return exc.retval; |
||
210 | } |
||
211 | return z; |
||
212 | #endif |
||
213 | } |
||
214 | |||
215 | #endif /* defined(_DOUBLE_IS_32BITS) */0.0&&rint(y)!=y)>0.0&&rint(y)!=y)>0.0)> |
||
216 |