On Mon, Apr 25, 2011 at 14:44, Jerry DeLisle <jvdeli...@frontier.com> wrote:
> On 04/25/2011 03:48 AM, Janne Blomqvist wrote:
>> Now, for one of the testcase changes:
>>
>> --- gcc/testsuite/gfortran.dg/char4_iunit_1.f03 (revision 172909)
>> +++ gcc/testsuite/gfortran.dg/char4_iunit_1.f03 (working copy)
>> @@ -24,11 +24,11 @@ program char4_iunit_1
>>    write(string, *) .true., .false. , .true.
>>    if (string .ne. 4_" T F T                                    ") call
>> abort
>>    write(string, *) 1.2345e-06, 4.2846e+10_8
>> -  if (string .ne. 4_"  1.23450002E-06   42846000000.000000     ") call
>> abort
>> +  if (string .ne. 4_"  1.234500019E-06   42846000000.000000    ") call
>> abort
>>
>> This looks wrong. For correctly rounded REAL(4) output, we need 9
>> significant digits, but here we print 10.
>>
>
> Well, I bumped it up for defaults based on pr48488 comment #2 shown below.

Yes, that comment in the PR is correct; to guarantee that a
binary->ascii->binary roundtrip preserves the original binary value
(with the default "round to nearest, break on even" rounding mode),
one must output at least {9, 17, 21, 36} significant digits for real
kinds 4, 8, 10, and 16, respectively (yes, I double-checked IEEE
754-2008 that this is indeed correct).

Since for the G edit descriptor d is equivalent to the number of
significant digits, AFAICS the write.c patch below is correct and the
bug must be elsewhere, no?


> Index: libgfortran/io/write.c
> ===================================================================
> --- libgfortran/io/write.c      (revision 172909)
> +++ libgfortran/io/write.c      (working copy)
> @@ -1432,8 +1432,8 @@ set_fnode_default (st_parameter_dt *dtp, fnode *f,
>   switch (length)
>     {
>     case 4:
> -      f->u.real.w = 15;
> -      f->u.real.d = 8;
> +      f->u.real.w = 16;
> +      f->u.real.d = 9;
>       f->u.real.e = 2;
>       break;
>     case 8:
> @@ -1442,13 +1442,13 @@ set_fnode_default (st_parameter_dt *dtp, fnode *f,
>       f->u.real.e = 3;
>       break;
>     case 10:
> -      f->u.real.w = 29;
> -      f->u.real.d = 20;
> +      f->u.real.w = 30;
> +      f->u.real.d = 21;
>       f->u.real.e = 4;
>       break;
>     case 16:
> -      f->u.real.w = 44;
> -      f->u.real.d = 35;
> +      f->u.real.w = 45;
> +      f->u.real.d = 36;
>       f->u.real.e = 4;
>       break;
>     default:
>



-- 
Janne Blomqvist

Reply via email to