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]

[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


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