This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: RFC: PR37472 bad output on default-format write of double in common block with -m64
On Sun, Dec 21, 2008 at 11:09:34PM -0800, Jerry DeLisle wrote:
> Steve Kargl wrote:
>
> >I suspect the problem lies in 0.1. It isn't exactly representable
> >and you're subject to rounding errors. Can you use
> >
> >temp = (calculate_exp_ ## x (mid) - 5 * calculate_exp_ ## x (mid - d - 1));
> >temp /= 10;
> >
>
> Steve, you hit the mark.
>
> This patch works:
>
> Index: write_float.def
> ===================================================================
> --- write_float.def (revision 142883)
> +++ write_float.def (working copy)
> @@ -640,7 +640,7 @@ output_float_FMT_G_ ## x (st_parameter_d
> GFC_REAL_ ## x temp;\
> mid = (low + high) / 2;\
> \
> - temp = 0.1 * calculate_exp_ ## x (mid) - 0.5\
> + temp = calculate_exp_ ## x (mid)/10 - 0.5\
> * calculate_exp_ ## x (mid - d - 1);\
> \
> if (m < temp)\
Looks good to me. For some unknown reason, I tend to think about
floating point and rounding errors more than I should.
--
Steve