summaryrefslogtreecommitdiff
path: root/Build/source/libs/mpfr/mpfr-src/src/uceil_log2.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/mpfr/mpfr-src/src/uceil_log2.c')
-rw-r--r--Build/source/libs/mpfr/mpfr-src/src/uceil_log2.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/Build/source/libs/mpfr/mpfr-src/src/uceil_log2.c b/Build/source/libs/mpfr/mpfr-src/src/uceil_log2.c
index 9c9168a5a91..700e0172a0a 100644
--- a/Build/source/libs/mpfr/mpfr-src/src/uceil_log2.c
+++ b/Build/source/libs/mpfr/mpfr-src/src/uceil_log2.c
@@ -24,40 +24,44 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
/* returns ceil(log(d)/log(2)) if d > 0,
-1023 if d = +0,
- and floor(log(-d)/log(2))+1 if d < 0*/
+ and floor(log(-d)/log(2))+1 if d < 0
+*/
long
__gmpfr_ceil_log2 (double d)
{
long exp;
-#if _GMP_IEEE_FLOATS
- union ieee_double_extract x;
+#if _MPFR_IEEE_FLOATS
+ union mpfr_ieee_double_extract x;
x.d = d;
- exp = x.s.exp - 1023;
+ /* The cast below is useless in theory, but let us not depend on the
+ integer promotion rules (for instance, tcc is currently wrong). */
+ exp = (long) x.s.exp - 1023;
+ MPFR_ASSERTN (exp < 1023); /* fail on infinities */
x.s.exp = 1023; /* value for 1 <= d < 2 */
if (x.d != 1.0) /* d: not a power of two? */
exp++;
return exp;
-#else
+#else /* _MPFR_IEEE_FLOATS */
double m;
if (d < 0.0)
- return __gmpfr_floor_log2(-d)+1;
+ return __gmpfr_floor_log2 (-d) + 1;
else if (d == 0.0)
return -1023;
else if (d >= 1.0)
{
exp = 0;
- for( m= 1.0 ; m < d ; m *=2.0 )
+ for (m = 1.0; m < d; m *= 2.0)
exp++;
}
else
{
exp = 1;
- for( m= 1.0 ; m >= d ; m *= (1.0/2.0) )
+ for (m = 1.0; m >= d; m *= 0.5)
exp--;
}
-#endif
+#endif /* _MPFR_IEEE_FLOATS */
return exp;
}