]>
Commit | Line | Data |
---|---|---|
48e44791 | 1 | /* Compute 2^x. |
6d7e8eda | 2 | Copyright (C) 2012-2023 Free Software Foundation, Inc. |
48e44791 JM |
3 | This file is part of the GNU C Library. |
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 | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
48e44791 | 18 | |
b6ab06ce | 19 | #include <math.h> |
9277c064 | 20 | #include <math_private.h> |
8f5b00d3 | 21 | #include <math-underflow.h> |
48e44791 | 22 | #include <float.h> |
b6ab06ce | 23 | |
7620dc12 GG |
24 | FLOAT |
25 | M_DECL_FUNC (__ieee754_exp2) (FLOAT x) | |
b6ab06ce | 26 | { |
7620dc12 | 27 | if (__glibc_likely (isless (x, (FLOAT) M_MAX_EXP))) |
48e44791 | 28 | { |
7620dc12 GG |
29 | if (__builtin_expect (isgreaterequal (x, (FLOAT) (M_MIN_EXP - M_MANT_DIG |
30 | - 1)), 1)) | |
48e44791 JM |
31 | { |
32 | int intx = (int) x; | |
7620dc12 GG |
33 | FLOAT fractx = x - intx; |
34 | FLOAT result; | |
35 | if (M_FABS (fractx) < M_EPSILON / 4) | |
36 | result = M_SCALBN (1 + fractx, intx); | |
903af5af | 37 | else |
33927914 | 38 | result = M_SCALBN (M_EXP (M_MLIT (M_LN2) * fractx), intx); |
d96164c3 | 39 | math_check_force_underflow_nonneg (result); |
903af5af | 40 | return result; |
48e44791 JM |
41 | } |
42 | else | |
43 | { | |
44 | /* Underflow or exact zero. */ | |
d81f90cc | 45 | if (isinf (x)) |
48e44791 JM |
46 | return 0; |
47 | else | |
7620dc12 | 48 | return M_MIN * M_MIN; |
48e44791 JM |
49 | } |
50 | } | |
51 | else | |
52 | /* Infinity, NaN or overflow. */ | |
7620dc12 | 53 | return M_MAX * x; |
b6ab06ce | 54 | } |
7620dc12 | 55 | declare_mgen_finite_alias (__ieee754_exp2, __exp2) |