OSDN Git Service

PR fortran/17190
authorpbrook <pbrook@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 25 Aug 2004 21:04:49 +0000 (21:04 +0000)
committerpbrook <pbrook@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 25 Aug 2004 21:04:49 +0000 (21:04 +0000)
* arith.c (gfc_mpfr_to_mpz): Workaround mpfr bug.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@86581 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/arith.c

index 85be102..dd6b48e 100644 (file)
@@ -1,5 +1,10 @@
 2004-08-25  Paul Brook  <paul@codesourcery.com>
 
+       PR fortran/17190
+       * arith.c (gfc_mpfr_to_mpz): Workaround mpfr bug.
+
+2004-08-25  Paul Brook  <paul@codesourcery.com>
+
        PR fortran/17144
        * trans-array.c (gfc_trans_allocate_temp_array): Remove
        string_length argument.
index 03ee14c..5f55813 100644 (file)
@@ -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);
 }