1 | /* Copyright (C) 2011-2020 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | Contributed by Ulrich Drepper <drepper@gmail.com>, 2011. |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see |
17 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <math.h> |
20 | #include <math_private.h> |
21 | #include <math-svid-compat.h> |
22 | #include <libm-alias-double.h> |
23 | |
24 | |
25 | #if LIBM_SVID_COMPAT && (SHLIB_COMPAT (libm, GLIBC_2_0, GLIBC_2_29) \ |
26 | || defined NO_LONG_DOUBLE \ |
27 | || defined LONG_DOUBLE_COMPAT) |
28 | /* wrapper pow */ |
29 | double |
30 | __pow_compat (double x, double y) |
31 | { |
32 | double z = __ieee754_pow (x, y); |
33 | if (__glibc_unlikely (!isfinite (z))) |
34 | { |
35 | if (_LIB_VERSION != _IEEE_) |
36 | { |
37 | if (isfinite (x) && isfinite (y)) |
38 | { |
39 | if (isnan (z)) |
40 | /* pow neg**non-int */ |
41 | return __kernel_standard (x, y, 24); |
42 | else if (x == 0.0 && y < 0.0) |
43 | { |
44 | if (signbit (x) && signbit (z)) |
45 | /* pow(-0.0,negative) */ |
46 | return __kernel_standard (x, y, 23); |
47 | else |
48 | /* pow(+0.0,negative) */ |
49 | return __kernel_standard (x, y, 43); |
50 | } |
51 | else |
52 | /* pow overflow */ |
53 | return __kernel_standard (x, y, 21); |
54 | } |
55 | } |
56 | } |
57 | else if (__builtin_expect (z == 0.0, 0) |
58 | && isfinite (x) && x != 0 && isfinite (y) |
59 | && _LIB_VERSION != _IEEE_) |
60 | /* pow underflow */ |
61 | return __kernel_standard (x, y, 22); |
62 | |
63 | return z; |
64 | } |
65 | # if SHLIB_COMPAT (libm, GLIBC_2_0, GLIBC_2_29) |
66 | compat_symbol (libm, __pow_compat, pow, GLIBC_2_0); |
67 | # endif |
68 | # ifdef NO_LONG_DOUBLE |
69 | weak_alias (__pow_compat, powl) |
70 | # endif |
71 | # ifdef LONG_DOUBLE_COMPAT |
72 | /* Work around gas bug "multiple versions for symbol". */ |
73 | weak_alias (__pow_compat, __pow_compat_alias) |
74 | |
75 | LONG_DOUBLE_COMPAT_CHOOSE_libm_powl ( |
76 | compat_symbol (libm, __pow_compat_alias, powl, FIRST_VERSION_libm_powl), ); |
77 | # endif |
78 | #endif |
79 | |