summaryrefslogtreecommitdiff
path: root/gcc/fortran/arith.c
diff options
context:
space:
mode:
authorPaul Brook <paul@codesourcery.com>2004-08-25 21:04:49 +0000
committerPaul Brook <pbrook@gcc.gnu.org>2004-08-25 21:04:49 +0000
commit9ca2b0db5726c53623f356754e5cc46985e7eaf8 (patch)
treec7fd5e49a0b365b2ea41fa2b7eb91f0548f5ef1c /gcc/fortran/arith.c
parentef79d4c27c8f603530fa8aca47380756c2f9137d (diff)
downloadgcc-9ca2b0db5726c53623f356754e5cc46985e7eaf8.tar.gz
re PR fortran/17190 (MPFR semantics for mpfr_get_z_exp changed)
PR fortran/17190 * arith.c (gfc_mpfr_to_mpz): Workaround mpfr bug. From-SVN: r86581
Diffstat (limited to 'gcc/fortran/arith.c')
-rw-r--r--gcc/fortran/arith.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/gcc/fortran/arith.c b/gcc/fortran/arith.c
index 03ee14c0999..5f558139401 100644
--- a/gcc/fortran/arith.c
+++ b/gcc/fortran/arith.c
@@ -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);
}