summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-06-07 00:44:56 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-06-07 00:44:56 +0000
commit85506fabed83a493972ca3654ad0d6f445148241 (patch)
treee1e154955eb40be54422252089c9ceb30723364d
parent7c540331f0126e634bd24c5d13f77ac1dfd5e862 (diff)
parent45abf6eaaf2b4986c138cc1a961466ee5d239ba2 (diff)
downloadmpfr-85506fabed83a493972ca3654ad0d6f445148241.tar.gz
Merged the latest changes from the trunk.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/ubf@10448 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--src/uceil_log2.c10
-rw-r--r--tests/tlgamma.c22
2 files changed, 28 insertions, 4 deletions
diff --git a/src/uceil_log2.c b/src/uceil_log2.c
index bfb799cae..7ee5166ae 100644
--- a/src/uceil_log2.c
+++ b/src/uceil_log2.c
@@ -33,7 +33,9 @@ __gmpfr_ceil_log2 (double d)
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;
x.s.exp = 1023; /* value for 1 <= d < 2 */
if (x.d != 1.0) /* d: not a power of two? */
exp++;
@@ -42,19 +44,19 @@ __gmpfr_ceil_log2 (double d)
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 /* _MPFR_IEEE_FLOATS */
diff --git a/tests/tlgamma.c b/tests/tlgamma.c
index 9d3689e95..3d686a6fc 100644
--- a/tests/tlgamma.c
+++ b/tests/tlgamma.c
@@ -385,11 +385,33 @@ mpfr_lgamma1 (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t r)
return mpfr_lgamma (y, &sign, x, r);
}
+/* Since r10377, the following test causes a "too much memory" error
+ when MPFR is built with Debian's tcc 0.9.27~git20151227.933c223-1
+ on x86_64. The problem came from __gmpfr_ceil_log2, now fixed in
+ r10443 (according to the integer promotion rules, this appeared to
+ be a bug in tcc, not in MPFR; however relying on such an obscure
+ rule was not a good idea). */
+static void
+tcc_bug20160606 (void)
+{
+ mpfr_t x, y;
+ int sign;
+
+ mpfr_init2 (x, 53);
+ mpfr_init2 (y, 53);
+ mpfr_set_ui_2exp (x, 1, -1, MPFR_RNDN);
+ mpfr_lgamma (y, &sign, x, MPFR_RNDN);
+ mpfr_clear (x);
+ mpfr_clear (y);
+}
+
int
main (void)
{
tests_start_mpfr ();
+ tcc_bug20160606 ();
+
special ();
test_generic (MPFR_PREC_MIN, 100, 2);