1*627f7eb2Smrg /* Compute 2^x.
2*627f7eb2Smrg Copyright (C) 2012-2018 Free Software Foundation, Inc.
3*627f7eb2Smrg This file is part of the GNU C Library.
4*627f7eb2Smrg
5*627f7eb2Smrg The GNU C Library is free software; you can redistribute it and/or
6*627f7eb2Smrg modify it under the terms of the GNU Lesser General Public
7*627f7eb2Smrg License as published by the Free Software Foundation; either
8*627f7eb2Smrg version 2.1 of the License, or (at your option) any later version.
9*627f7eb2Smrg
10*627f7eb2Smrg The GNU C Library is distributed in the hope that it will be useful,
11*627f7eb2Smrg but WITHOUT ANY WARRANTY; without even the implied warranty of
12*627f7eb2Smrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13*627f7eb2Smrg Lesser General Public License for more details.
14*627f7eb2Smrg
15*627f7eb2Smrg You should have received a copy of the GNU Lesser General Public
16*627f7eb2Smrg License along with the GNU C Library; if not, see
17*627f7eb2Smrg <http://www.gnu.org/licenses/>. */
18*627f7eb2Smrg
19*627f7eb2Smrg #include "quadmath-imp.h"
20*627f7eb2Smrg
21*627f7eb2Smrg __float128
exp2q(__float128 x)22*627f7eb2Smrg exp2q (__float128 x)
23*627f7eb2Smrg {
24*627f7eb2Smrg if (__glibc_likely (__builtin_isless (x, (__float128) FLT128_MAX_EXP)))
25*627f7eb2Smrg {
26*627f7eb2Smrg if (__builtin_expect (__builtin_isgreaterequal (x, (__float128) (FLT128_MIN_EXP - FLT128_MANT_DIG
27*627f7eb2Smrg - 1)), 1))
28*627f7eb2Smrg {
29*627f7eb2Smrg int intx = (int) x;
30*627f7eb2Smrg __float128 fractx = x - intx;
31*627f7eb2Smrg __float128 result;
32*627f7eb2Smrg if (fabsq (fractx) < FLT128_EPSILON / 4)
33*627f7eb2Smrg result = scalbnq (1 + fractx, intx);
34*627f7eb2Smrg else
35*627f7eb2Smrg result = scalbnq (expq (M_LN2q * fractx), intx);
36*627f7eb2Smrg math_check_force_underflow_nonneg (result);
37*627f7eb2Smrg return result;
38*627f7eb2Smrg }
39*627f7eb2Smrg else
40*627f7eb2Smrg {
41*627f7eb2Smrg /* Underflow or exact zero. */
42*627f7eb2Smrg if (isinfq (x))
43*627f7eb2Smrg return 0;
44*627f7eb2Smrg else
45*627f7eb2Smrg return FLT128_MIN * FLT128_MIN;
46*627f7eb2Smrg }
47*627f7eb2Smrg }
48*627f7eb2Smrg else
49*627f7eb2Smrg /* Infinity, NaN or overflow. */
50*627f7eb2Smrg return FLT128_MAX * x;
51*627f7eb2Smrg }
52