This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[fortran,patch] Call mpfr_check_range after setting emin/emax
- From: FX <fxcoudert at gmail dot com>
- To: Fortran List <fortran at gcc dot gnu dot org>, "gcc-patches at gcc dot gnu dot org patches" <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 1 May 2008 00:34:08 +0100
- Subject: [fortran,patch] Call mpfr_check_range after setting emin/emax
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:mime-version:content-transfer-encoding:message-id:content-type:to:from:subject:date:x-mailer; bh=9cgROQjQTvbxigWpy1vWKgZYjVlyrLZl6ZeUkIeJuHo=; b=TqpYFHT2Gl+4tA3gjZpyM2JyQ0wfGsEshOMRgOuyzQG6hhjdi/F+QjugHrFYaw1g5YRCnlDM8x11V0zgvNqgvBHrlBZT8vizkGHlfMqU5+um9iembX+F9zapi5n8G8qapIKwzR3rH9tkx1wzSQ5Zzi6BkPSgx0CNFUnVJZuEMj4=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:content-transfer-encoding:message-id:content-type:to:from:subject:date:x-mailer; b=wXrlSWpmweJkniGxyGzEzvwLNHSkPSAnt+t+K4RbxlbXGkC8Dod6iXvFBCLNkfg6Fb5BW3K7arGAuFvHYiTzrvZT/6uHM2/lT5R2TU38Re+/l6FAnVtxfYnPSj1i19mK07Hxiu2qgQ7u69TexbI3jZyNJ3RoQxrjbCev470ohTM=
For a few months now, I've seen a failure of gfortran.dg/
nearest_4.f90 on my x86_64-linux build machine; the fact that noone
else saw it, I suppose, is because I use GMP and MPFR built with
internal checking (assertions) enabled. The following patch fixes it:
Index: simplify.c
===================================================================
--- simplify.c (revision 134839)
+++ simplify.c (working copy)
@@ -2821,6 +2821,7 @@ gfc_simplify_nearest (gfc_expr *x, gfc_e
mpfr_set_emin ((mp_exp_t) gfc_real_kinds[kind].min_exponent -
mpfr_get_prec(result->value.real) + 1);
mpfr_set_emax ((mp_exp_t) gfc_real_kinds[kind].max_exponent - 1);
+ mpfr_check_range (result->value.real, 0, GMP_RNDU);
if (mpfr_sgn (s->value.real) > 0)
{
It follows the MPFR doc, which says that it's our responsability to
make sure a real number is still in range after we've used mpfr_set_e
{min,max}. These functions are used in another place in arith.c,
which I propose to also fix:
Index: arith.c
===================================================================
--- arith.c (revision 134839)
+++ arith.c (working copy)
@@ -384,6 +384,7 @@ gfc_check_real_range (mpfr_t p, int kind
en = gfc_real_kinds[i].min_exponent - gfc_real_kinds
[i].digits + 1;
mpfr_set_emin ((mp_exp_t) en);
mpfr_set_emax ((mp_exp_t) gfc_real_kinds[i].max_exponent);
+ mpfr_check_range (q, 0, GFC_RND_MODE);
mpfr_subnormalize (q, 0, GFC_RND_MODE);
/* Reset emin and emax. */
I will regtest and keep you posted, but does someone have an
objection on the principle of it, or does it sound like the right fix?
FX
--
François-Xavier Coudert
http://www.homepages.ucl.ac.uk/~uccafco/