3 /* @(#)w_pow.c 5.2 93/10/01 */
5 * ====================================================
6 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 * Developed at SunPro, a Sun Microsystems, Inc. business.
9 * Permission to use, copy, modify, and distribute this
10 * software is freely granted, provided that this notice
12 * ====================================================
17 <<pow>>, <<powf>>---x to the power y
26 double pow(double <[x]>, double <[y]>);
27 float pow(float <[x]>, float <[y]>);
31 double pow(<[x]>, <[y]>);
34 float pow(<[x]>, <[y]>);
38 <<pow>> and <<powf>> calculate <[x]> raised to the exp1.0nt <[y]>.
44 On success, <<pow>> and <<powf>> return the value calculated.
46 When the argument values would produce overflow, <<pow>>
47 returns <<HUGE_VAL>> and set <<errno>> to <<ERANGE>>. If the
48 argument <[x]> passed to <<pow>> or <<powf>> is a negative
49 noninteger, and <[y]> is also not an integer, then <<errno>>
50 is set to <<EDOM>>. If <[x]> and <[y]> are both 0, then
51 <<pow>> and <<powf>> return <<1>>.
53 You can modify error handling for these functions using <<matherr>>.
56 <<pow>> is ANSI C. <<powf>> is an extension. */
59 * wrapper pow(x,y) return x**y
65 #ifndef _DOUBLE_IS_32BITS
68 double pow(double x
, double y
) /* wrapper pow */
70 double pow(x
,y
) /* wrapper pow */
75 return __ieee754_pow(x
,y
);
82 SET_HIGH_WORD(inf
,0x7ff00000); /* set inf to infinite */
86 if(_LIB_VERSION
== _IEEE_
|| isnan(y
)) return z
;
90 /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
97 if (_LIB_VERSION
== _IEEE_
||
98 _LIB_VERSION
== _POSIX_
) exc
.retval
= 1.0;
99 else if (!matherr(&exc
)) {
111 /* error only if _LIB_VERSION == _SVID_ */
118 if (_LIB_VERSION
!= _SVID_
) exc
.retval
= 1.0;
119 else if (!matherr(&exc
)) {
126 if(finite(y
)&&y
<0.0) {
133 if (_LIB_VERSION
== _SVID_
)
136 exc
.retval
= -HUGE_VAL
;
137 if (_LIB_VERSION
== _POSIX_
)
139 else if (!matherr(&exc
)) {
149 if(finite(x
)&&finite(y
)) {
151 /* neg**non-integral */
157 if (_LIB_VERSION
== _SVID_
)
160 exc
.retval
= 0.0/0.0; /* X/Open allow NaN */
161 if (_LIB_VERSION
== _POSIX_
)
163 else if (!matherr(&exc
)) {
170 /* pow(x,y) overflow */
176 if (_LIB_VERSION
== _SVID_
) {
179 if(x
<0.0&&rint(y
)!=y
) exc
.retval
= -HUGE
;
181 exc
.retval
= HUGE_VAL
;
183 if(x
<0.0&&rint(y
)!=y
) exc
.retval
= -HUGE_VAL
;
185 if (_LIB_VERSION
== _POSIX_
)
187 else if (!matherr(&exc
)) {
196 if(z
==0.0&&finite(x
)&&finite(y
)) {
197 /* pow(x,y) underflow */
198 exc
.type
= UNDERFLOW
;
204 if (_LIB_VERSION
== _POSIX_
)
206 else if (!matherr(&exc
)) {
217 #endif /* defined(_DOUBLE_IS_32BITS) */