2 * Single-precision 2^x function.
4 * Copyright (c) 2017-2018, Arm Limited.
5 * SPDX-License-Identifier: MIT
10 #include "math_config.h"
16 ULP error: 0.502 (nearest rounding.)
17 Relative error: 1.69 * 2^-34 in [-1/64, 1/64] (before rounding.)
18 Wrong count: 168353 (all nearest rounding wrong results with fma.)
19 Non-nearest ULP error: 1 (rounded ULP error)
22 #define N (1 << EXP2F_TABLE_BITS)
23 #define T __exp2f_data.tab
24 #define C __exp2f_data.poly
25 #define SHIFT __exp2f_data.shift_scaled
27 static inline uint32_t
30 return asuint (x) >> 20;
38 /* double_t for better performance on targets with FLT_EVAL_METHOD==2. */
39 double_t kd, xd, z, r, r2, y, s;
42 abstop = top12 (x) & 0x7ff;
43 if (unlikely (abstop >= top12 (128.0f)))
45 /* |x| >= 128 or x is nan. */
46 if (asuint (x) == asuint (-INFINITY))
48 if (abstop >= top12 (INFINITY))
51 return __math_oflowf (0);
53 return __math_uflowf (0);
56 return __math_may_uflowf (0);
60 /* x = k/N + r with r in [-1/(2N), 1/(2N)] and int k. */
61 kd = eval_as_double (xd + SHIFT);
63 kd -= SHIFT; /* k/N for int k. */
66 /* exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1) */
68 t += ki << (52 - EXP2F_TABLE_BITS);
75 return eval_as_float (y);
78 strong_alias (exp2f, __exp2f_finite)
79 hidden_alias (exp2f, __ieee754_exp2f)