2012-03-22 12:55:19 +00:00
|
|
|
/* Compute 2^x.
|
2017-01-01 00:14:16 +00:00
|
|
|
Copyright (C) 2012-2017 Free Software Foundation, Inc.
|
2012-03-22 12:55:19 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
|
2005-12-14 08:43:25 +00:00
|
|
|
#include <math.h>
|
2011-10-08 09:16:04 +00:00
|
|
|
#include <math_private.h>
|
2012-03-22 12:55:19 +00:00
|
|
|
#include <float.h>
|
2005-12-14 08:43:25 +00:00
|
|
|
|
2017-05-16 16:34:34 +00:00
|
|
|
#define declare_mgen_finite_alias_x(from, to) \
|
|
|
|
strong_alias (from, to ## _finite)
|
|
|
|
#define declare_mgen_finite_alias_s(from,to) \
|
|
|
|
declare_mgen_finite_alias_x (from, to)
|
|
|
|
#define declare_mgen_finite_alias(from, to) \
|
|
|
|
declare_mgen_finite_alias_s (M_SUF (from), M_SUF (to))
|
2015-02-12 19:02:45 +00:00
|
|
|
|
2017-05-16 16:34:34 +00:00
|
|
|
FLOAT
|
|
|
|
M_DECL_FUNC (__ieee754_exp2) (FLOAT x)
|
2005-12-14 08:43:25 +00:00
|
|
|
{
|
2017-05-16 16:34:34 +00:00
|
|
|
if (__glibc_likely (isless (x, (FLOAT) M_MAX_EXP)))
|
2012-03-22 12:55:19 +00:00
|
|
|
{
|
2017-05-16 16:34:34 +00:00
|
|
|
if (__builtin_expect (isgreaterequal (x, (FLOAT) (M_MIN_EXP - M_MANT_DIG
|
|
|
|
- 1)), 1))
|
2012-03-22 12:55:19 +00:00
|
|
|
{
|
|
|
|
int intx = (int) x;
|
2017-05-16 16:34:34 +00:00
|
|
|
FLOAT fractx = x - intx;
|
|
|
|
FLOAT result;
|
|
|
|
if (M_FABS (fractx) < M_EPSILON / 4)
|
|
|
|
result = M_SCALBN (1 + fractx, intx);
|
2015-09-14 22:00:12 +00:00
|
|
|
else
|
2017-05-16 16:34:34 +00:00
|
|
|
result = M_SCALBN (M_EXP (M_SUF (M_LN2) * fractx), intx);
|
2015-09-23 22:42:30 +00:00
|
|
|
math_check_force_underflow_nonneg (result);
|
2015-09-14 22:00:12 +00:00
|
|
|
return result;
|
2012-03-22 12:55:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Underflow or exact zero. */
|
2015-06-03 14:36:34 +00:00
|
|
|
if (isinf (x))
|
2012-03-22 12:55:19 +00:00
|
|
|
return 0;
|
|
|
|
else
|
2017-05-16 16:34:34 +00:00
|
|
|
return M_MIN * M_MIN;
|
2012-03-22 12:55:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* Infinity, NaN or overflow. */
|
2017-05-16 16:34:34 +00:00
|
|
|
return M_MAX * x;
|
2005-12-14 08:43:25 +00:00
|
|
|
}
|
2017-05-16 16:34:34 +00:00
|
|
|
declare_mgen_finite_alias (__ieee754_exp2, __exp2)
|