1 /* Single-precision 2^x function.
2 Copyright (C) 2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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 <http://www.gnu.org/licenses/>. */
21 #include <shlib-compat.h>
22 #include <libm-alias-float.h>
23 #include "math_config.h"
29 ULP error: 0.502 (nearest rounding.)
30 Relative error: 1.69 * 2^-34 in [-1/64, 1/64] (before rounding.)
31 Wrong count: 168353 (all nearest rounding wrong results with fma.)
32 Non-nearest ULP error: 1 (rounded ULP error)
35 #define N (1 << EXP2F_TABLE_BITS)
36 #define T __exp2f_data.tab
37 #define C __exp2f_data.poly
38 #define SHIFT __exp2f_data.shift_scaled
40 static inline uint32_t
43 return asuint (x
) >> 20;
51 /* double_t for better performance on targets with FLT_EVAL_METHOD==2. */
52 double_t kd
, xd
, z
, r
, r2
, y
, s
;
55 abstop
= top12 (x
) & 0x7ff;
56 if (__glibc_unlikely (abstop
>= top12 (128.0f
)))
58 /* |x| >= 128 or x is nan. */
59 if (asuint (x
) == asuint (-INFINITY
))
61 if (abstop
>= top12 (INFINITY
))
64 return __math_oflowf (0);
66 return __math_uflowf (0);
69 return __math_may_uflowf (0);
73 /* x = k/N + r with r in [-1/(2N), 1/(2N)] and int k. */
74 kd
= math_narrow_eval ((double) (xd
+ SHIFT
)); /* Needs to be double. */
76 kd
-= SHIFT
; /* k/N for int k. */
79 /* exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1) */
81 t
+= ki
<< (52 - EXP2F_TABLE_BITS
);
91 strong_alias (__exp2f
, __ieee754_exp2f
)
92 strong_alias (__exp2f
, __exp2f_finite
)
93 versioned_symbol (libm
, __exp2f
, exp2f
, GLIBC_2_27
);
94 libm_alias_float_other (__exp2
, exp2
)