This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
RFC: PR37472 bad output on default-format write of double in common block with -m64
- From: Jerry DeLisle <jvdelisle at verizon dot net>
- To: Fortran List <fortran at gcc dot gnu dot org>
- Date: Sun, 21 Dec 2008 21:46:51 -0800
- Subject: RFC: PR37472 bad output on default-format write of double in common block with -m64
Hi all,
This is an interesting bug. On x86-64 I can see a shift of the placement of the
decimal point in formatted output of kind=8 and kind=10 reals between using -m64
and -m32. The incorrect output appears with -m32.
The attached patch appears to fix this. The only part of the patch that seems
essential is changing the type of temp to GFC_REAL_4 rather than have the type
match the type of the variable being output. GFC_REAL_4 is C type float.
I have tried several variations of the macros, passing in the L descriptor and
do not see it makes any difference. I am open to suggestions here or any
further insight.
The patch is fully regression tested at -m32 and -m64 so I think it is safe.
Shall I commit?
Regards,
Jerry
Index: write_float.def
===================================================================
--- write_float.def (revision 142883)
+++ write_float.def (working copy)
@@ -556,28 +556,28 @@ write_infnan (st_parameter_dt *dtp, cons
/* Returns the value of 10**d. */
-#define CALCULATE_EXP(x) \
+#define CALCULATE_EXP(x,y) \
inline static GFC_REAL_ ## x \
calculate_exp_ ## x (int d)\
{\
int i;\
- GFC_REAL_ ## x r = 1.0;\
+ GFC_REAL_ ## x r = 1.0 ## y;\
for (i = 0; i< (d >= 0 ? d : -d); i++)\
- r *= 10;\
+ r *= 10.0 ## y;\
r = (d >= 0) ? r : 1.0 / r;\
return r;\
}
-CALCULATE_EXP(4)
+CALCULATE_EXP(4,)
-CALCULATE_EXP(8)
+CALCULATE_EXP(8,)
#ifdef HAVE_GFC_REAL_10
-CALCULATE_EXP(10)
+CALCULATE_EXP(10,L)
#endif
#ifdef HAVE_GFC_REAL_16
-CALCULATE_EXP(16)
+CALCULATE_EXP(16,L)
#endif
#undef CALCULATE_EXP
@@ -637,11 +637,11 @@ output_float_FMT_G_ ## x (st_parameter_d
\
while (low <= high)\
{ \
- GFC_REAL_ ## x temp;\
+ GFC_REAL_4 temp;\
mid = (low + high) / 2;\
\
temp = 0.1 * calculate_exp_ ## x (mid) - 0.5\
- * calculate_exp_ ## x (mid - d - 1);\
+ * calculate_exp_4 (mid - d - 1);\
\
if (m < temp)\
{ \