This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gfortran] PR libfortran/21376


FX Coudert wrote:
> Attached patch fixes PR libfortran/21376 (library called log10 with 
> argument equal to zero). Simple reworking of logic to avoid that.
> 
> Regtesting in progress on i686-linux. OK for 4.0 and mainline?

How about this slightly simpler patch which collects all the special cases in
one place.  Bubblestrapped and tested, OK for 4.0 and mainline?

- Tobi

2005-05-22  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/21376
	* io/write.c (output_float): Collect all special cases for exponent
	in one place.


! { dg-do run }
! PR 21376
! we used to take the logarrithm of zero in this special case
character*10 c
write(c,'(e10.4)') 1.0
if(c /= "0.1000E+01") call abort
write(c,'(e10.4)') 0.0
if(c /= "0.0000E+00") call abort
write(c,'(e10.4)') 100.0
if(c /= "0.1000E+03") call abort
write(c,'(e10.4)') .01
if(c /= "0.1000E-01") call abort
end
Index: write.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/io/write.c,v
retrieving revision 1.37
diff -c -3 -p -r1.37 write.c
*** write.c	17 May 2005 16:54:51 -0000	1.37
--- write.c	22 May 2005 22:46:43 -0000
*************** output_float (fnode *f, double value)
*** 315,329 ****
    if (value < 0)
      value = -value;
  
!   /* Printf always prints at least two exponent digits.  */
!   if (value == 0)
      edigits = 2;
    else
!     {
!       edigits = 1 + (int) log10 (fabs(log10 (value)));
!       if (edigits < 2)
! 	edigits = 2;
!     }
  
    if (ft == FMT_F || ft == FMT_EN
        || ((ft == FMT_D || ft == FMT_E) && g.scale_factor != 0))
--- 315,326 ----
    if (value < 0)
      value = -value;
  
!   /* Printf always prints at least two exponent digits.  Also handle
!      the special case of zero correctly.  */
!   if (value == 0 || (value < 100 && value > 0.01))
      edigits = 2;
    else
!     edigits = 1 + (int) log10 (fabs (log10 (value)));
  
    if (ft == FMT_F || ft == FMT_EN
        || ((ft == FMT_D || ft == FMT_E) && g.scale_factor != 0))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]