This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gfortran] Fix MPFR bug


Version 2.0.1 of MPFR (included with GMP4.1) contains a bug in mpfr_get_z_exp. 
It always sets x to a positive value. I happen to have this buggy version, 
and assumed it was a feature:)

Patch below works around the bug in a way that doesn't break newer (fixed) 
version.

Tested on i686-linux.
Applied to mainline.

Paul

2004-08-25  Paul Brook  <paul@codesourcery.com>

	PR fortran/17190
	* arith.c (gfc_mpfr_to_mpz): Workaround mpfr bug.

Index: arith.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/fortran/arith.c,v
retrieving revision 1.11
diff -u -p -r1.11 arith.c
--- arith.c	6 Aug 2004 20:36:04 -0000	1.11
+++ arith.c	25 Aug 2004 20:50:22 -0000
@@ -106,17 +106,20 @@ int gfc_index_integer_kind;
    It's easily implemented with a few calls though.  */
 
 void
-gfc_mpfr_to_mpz(mpz_t z, mpfr_t x)
+gfc_mpfr_to_mpz (mpz_t z, mpfr_t x)
 {
   mp_exp_t e;
 
   e = mpfr_get_z_exp (z, x);
+  /* MPFR 2.0.1 (included with GMP 4.1) has a bug whereby mpfr_get_z_exp
+     may set the sign of z incorrectly.  Work around that here.  */
+  if (mpfr_sgn (x) != mpz_sgn (z))
+    mpz_neg (z, z);
+
   if (e > 0)
     mpz_mul_2exp (z, z, e);
   else
     mpz_tdiv_q_2exp (z, z, -e);
-  if (mpfr_sgn (x) < 0)
-    mpz_neg (z, z);
 }
 
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]