This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[Committed] fortran/arith.c -- Fix handling of subnormal numbers.
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 3 Oct 2006 14:31:38 -0700
- Subject: [Committed] fortran/arith.c -- Fix handling of subnormal numbers.
I've committed the following patch as obvious. In handling subnormal
numbers within mpfr, one needs to set an exponent range. In the
old code, I had set emin and emax to the values corresponding to the
Fortran model number minus 1 (ie., emin-1, emax-1). In fact, the
range should have been emin-p+1 and emax where p is the precision.
This range allows the desired gradual underflow.
2006-10-03 Steven G. Kargl <kargl@gcc.gnu.org>
* arith.c (gfc_check_real_range): Use correct exponent range for
subnormal numbers.
Index: arith.c
===================================================================
--- arith.c (revision 117413)
+++ arith.c (working copy)
@@ -438,14 +438,16 @@ gfc_check_real_range (mpfr_t p, int kind
gfc_free (bin);
#else
mp_exp_t emin, emax;
+ int en;
/* Save current values of emin and emax. */
emin = mpfr_get_emin ();
emax = mpfr_get_emax ();
/* Set emin and emax for the current model number. */
- mpfr_set_emin ((mp_exp_t) gfc_real_kinds[i].min_exponent - 1);
- mpfr_set_emax ((mp_exp_t) gfc_real_kinds[i].max_exponent - 1);
+ 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_subnormalize (q, 0, GFC_RND_MODE);
/* Reset emin and emax. */
--
Steve