2 This Software is provided under the Zope Public License (ZPL) Version 2.1.
4 Copyright (c) 2009, 2010 by the mingw-w64 project
6 See the AUTHORS file for the list of contributors to the mingw-w64 project.
8 This license has been certified as open source. It has also been designated
9 as GPL compatible by the Free Software Foundation (FSF).
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
14 1. Redistributions in source code must retain the accompanying copyright
15 notice, this list of conditions, and the following disclaimer.
16 2. Redistributions in binary form must reproduce the accompanying
17 copyright notice, this list of conditions, and the following disclaimer
18 in the documentation and/or other materials provided with the
20 3. Names of the copyright holders must not be used to endorse or promote
21 products derived from this software without prior written permission
22 from the copyright holders.
23 4. The right to distribute this software or to use it for any purpose does
24 not give you the right to use Servicemarks (sm) or Trademarks (tm) of
25 the copyright holders. Use of them is covered by separate agreement
26 with the copyright holders.
27 5. If any files are modified, you must cause the modified files to carry
28 prominent notices stating that you changed the files and the date of
33 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
34 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
36 EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
37 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
39 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
40 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
42 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 /* IEEE 754 - Elementary Functions - Special Cases
46 * powi (x, +/-0) is 1 for any x (even a zero, quiet NaN, or infinity)
47 * powi (+1, y) is 1 for any y (even a quiet NaN)
48 * powi (+/-0, y) is +/-oo and signals the divideByZero exception for y an odd integer < 0
49 * powi (+/-0, y) is +oo and signals the divideByZero exception for finite y < 0 and not an odd integer
50 * powi (+/-0, y) is +/-0 for finite y > 0 an odd integer
51 * powi (+/-0, y) is +0 for finite y > 0 and not an odd integer
52 powi (-inf, y) = +0 for y<0 and not an odd integer
53 powi (-inf, y) = -inf for y an odd integer > 0
54 powi (-inf, y) = +inf for y>0 and not an odd integer
55 powi (+/-inf, y) is +/-0 with no exception for y an odd integer < 0
56 powi (+/-inf, y) is +0 with no exception for finite y < 0 and not an odd integer
57 powi (+/-inf, y) is +/-inf with no exception for finite y > 0 an odd integer
58 powi (+/-inf, y) is +inf with no exception for finite y > 0 and not an odd integer
59 powi (x, y) signals the invalid operation exception for finite x < 0 and finite non-integer y.
61 For x /= 0: lim y->oo (1/x)^y results as: for |x| < 1 that sgn(x)*0 and for |x| > 0 that sgn(x)*Infinity
64 #include "complex_internal.h"
72 __FLT_ABI(__powi
) (__FLT_TYPE x
, int y
);
75 __FLT_ABI(__powi
) (__FLT_TYPE x
, int y
)
77 int x_class
= fpclassify (x
);
81 if (y
== 0 || x
== __FLT_CST(1.0))
82 return __FLT_CST(1.0);
83 else if (x_class
== FP_NAN
)
85 rslt
= (signbit(x
) ? -__FLT_NAN
: __FLT_NAN
);
89 else if (x_class
== FP_ZERO
)
93 if (!odd_y
|| !signbit (x
))
94 return __FLT_CST (0.0);
95 return -__FLT_CST(0.0);
98 if (!odd_y
|| !signbit (x
))
99 return __FLT_HUGE_VAL
;
100 return (signbit(x
) ? -__FLT_HUGE_VAL
: __FLT_HUGE_VAL
);
102 else if (x_class
== FP_INFINITE
)
104 /* pow( -inf, y) = +0 for y<0 and not an odd integer, */
105 if (signbit(x
) && y
< 0 && !odd_y
)
106 return __FLT_CST(0.0);
107 /* pow( -inf, y) = -inf for y an odd integer > 0. */
108 if (signbit(x
) && y
>= 0 && odd_y
)
109 return -__FLT_HUGE_VAL
;
110 /* pow( -inf, y) = +inf for y>0 and not an odd integer. */
111 if (signbit(x
) && y
>= 0 && !odd_y
)
112 return __FLT_HUGE_VAL
;
113 /* pow (+/-inf, y) is +/-0 with no exception for y an odd integer < 0. */
116 /* pow (+/-inf, y) is +0 with no exception for finite y < 0 and not an odd integer. */
117 return (odd_y
&& signbit(x
) ? -__FLT_CST(0.0) : __FLT_CST(0.0));
119 /* pow (+/-inf, y) is +/-inf with no exception for finite y > 0 an odd integer. */
120 /* pow (+/-inf, y) is +inf with no exception for finite y > 0 and not an odd integer. */
121 return (odd_y
&& signbit(x
) ? -__FLT_HUGE_VAL
: __FLT_HUGE_VAL
);
124 d
= __FLT_ABI(fabs
) (x
);
128 d
= __FLT_CST(1.0) / d
;
133 rslt
= __FLT_CST(1.0);
138 unsigned int u
= (unsigned int) y
;
139 rslt
= ((u
& 1) != 0) ? d
: __FLT_CST(1.0);
150 if (signbit (x
) && odd_y
)