[fortran] huge() vs IBM extended double
Alan Modra
amodra@bigpond.net.au
Sun Nov 6 03:24:00 GMT 2005
:ADDPATCH fortran:
huge() currently returns +Inf on targets using IBM extended long
doubles. Not understanding fortran's "model numbers", I originally
submitted a patch to correct this by making huge() return the same value
as C's __LDBL_MAX__. Apparently the right fix is to reduce emax by
one. See
http://gcc.gnu.org/ml/fortran/2005-09/msg00556.html
http://gcc.gnu.org/ml/fortran/2005-09/msg00562.html
http://gcc.gnu.org/ml/fortran/2005-09/msg00564.html
Bootstrapped and regression tested powerpc64-linux, with 128-bit long
doubles enabled.
PR fortran/24096
* trans-types.c (gfc_init_kinds): Use one less for max_exponent
of IBM extended double format.
Index: gcc/fortran/trans-types.c
===================================================================
--- gcc/fortran/trans-types.c (revision 106520)
+++ gcc/fortran/trans-types.c (working copy)
@@ -192,6 +192,15 @@
gfc_real_kinds[r_index].digits = fmt->p;
gfc_real_kinds[r_index].min_exponent = fmt->emin;
gfc_real_kinds[r_index].max_exponent = fmt->emax;
+ if (fmt->pnan < fmt->p)
+ /* This is an IBM extended double format made up of two IEEE
+ doubles. The value of the long double is the sum of the
+ values of the two parts. The most significant part is
+ required to be the value of the long double rounded to the
+ nearest double. If we use emax of 1024 then we can't
+ represent huge(x) = (1 - b**(-p)) * b**(emax-1) * b, because
+ rounding will make the most significant part overflow. */
+ gfc_real_kinds[r_index].max_exponent = fmt->emax - 1;
gfc_real_kinds[r_index].mode_precision = GET_MODE_PRECISION (mode);
r_index += 1;
}
--
Alan Modra
IBM OzLabs - Linux Technology Centre
More information about the Fortran
mailing list