diff mbox

[libgfortran] Bug 57822 - I/O: "(g0)" wrongly prints "E+0000"

Message ID 54D80914.80500@charter.net
State New
Headers show

Commit Message

Jerry DeLisle Feb. 9, 2015, 1:10 a.m. UTC
The attached patch fixes this by checking for the case when we are doing g0 
editing and the exponent is 0.

Regression tested on X86-64.  For the larger kinds, we are on a different code 
path out of necessity, so we need to address this corner case.

I will commit in a day or two as simple/obvious, with a Changelog for the 
testsuite as well.

Regards,

Jerry

2015-02-09  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/57822
	* io/write_float.def (output_float): If doing g0 editing and
	exponent is zero, do not emit exponent.
! { dg-do run }
! PR58722
program testit
  character(50) :: astring
  
  write(astring, '(g0)') 0.1_4
  if (test(astring)) call abort
  write(astring, '(g0)') 0.1_8
  if (test(astring)) call abort
  write(astring, '(g0)') 0.1_10
  if (test(astring)) call abort
  write(astring, '(g0)') 0.1_16
  if (test(astring)) call abort

contains

function test (string1) result(res)
  character(len=*) :: string1
  logical :: res

  res = .true.
  do i = 1, len(string1)
    if (string1(i:i) == 'E') return
  end do
  res = .false.
end function

end program

Comments

Jerry DeLisle Feb. 11, 2015, 4:46 a.m. UTC | #1
On 02/08/2015 05:10 PM, Jerry DeLisle wrote:
> The attached patch fixes this by checking for the case when we are doing g0
> editing and the exponent is 0.
>
> Regression tested on X86-64.  For the larger kinds, we are on a different code
> path out of necessity, so we need to address this corner case.
>

I committed this followup to correct an omission I made.

Sending        ChangeLog
Sending        io/write_float.def
Transmitting file data ..
Committed revision 220606.

2015-02-10 Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/57822
	* io/write_float.def (output_float): Apply fix of previous patch
	to correctly calculate the exponent number of digits and take
	care of wide character output.
Jakub Jelinek Feb. 11, 2015, 1:04 p.m. UTC | #2
On Sun, Feb 08, 2015 at 05:10:44PM -0800, Jerry DeLisle wrote:
> The attached patch fixes this by checking for the case when we are doing g0
> editing and the exponent is 0.
> 
> Regression tested on X86-64.  For the larger kinds, we are on a different
> code path out of necessity, so we need to address this corner case.
> 
> I will commit in a day or two as simple/obvious, with a Changelog for the
> testsuite as well.

The test fails on most of the architectures.
Not all targets support _10 or _16.

	Jakub
Jakub Jelinek Feb. 11, 2015, 1:08 p.m. UTC | #3
On Wed, Feb 11, 2015 at 02:04:09PM +0100, Jakub Jelinek wrote:
> On Sun, Feb 08, 2015 at 05:10:44PM -0800, Jerry DeLisle wrote:
> > The attached patch fixes this by checking for the case when we are doing g0
> > editing and the exponent is 0.
> > 
> > Regression tested on X86-64.  For the larger kinds, we are on a different
> > code path out of necessity, so we need to address this corner case.
> > 
> > I will commit in a day or two as simple/obvious, with a Changelog for the
> > testsuite as well.
> 
> The test fails on most of the architectures.
> Not all targets support _10 or _16.

For _16 you'd need to guard the test with fortran_real_16 (perhaps split
that part into a separate test), for _10 dunno.

	Jakub
diff mbox

Patch

Index: write_float.def
===================================================================
--- write_float.def	(revision 220505)
+++ write_float.def	(working copy)
@@ -724,7 +724,7 @@ 
     }
 
   /* Output the exponent.  */
-  if (expchar)
+  if (expchar && !(dtp->u.p.g0_no_blanks && e == 0))
     {
       if (expchar != ' ')
 	{