Bug 28354 - [4.1 Only] 0.99999 printed as 0. instead of 1. by format(f3.0)
Summary: [4.1 Only] 0.99999 printed as 0. instead of 1. by format(f3.0)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.1.1
: P3 major
Target Milestone: 4.2.0
Assignee: Jerry DeLisle
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2006-07-12 08:13 UTC by Enrico Segre
Modified: 2007-04-28 16:31 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-08-22 00:25:42


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Enrico Segre 2006-07-12 08:13:08 UTC
Compiling the following snippet

       write(*,100) 0.99999
       write(*,100) 0.999999
       write(*,100) 0.9999999
       write(*,100) 0.99999999
       write(*,100) 0.999999999
       write(*,100) 0.9999999999
 100   format((f3.0))
       end

with gcc-gfortran-4.1.1-1.fc5, I get as output

   0.
   0.
   0.
   1.
   1.
   1.


I get similar faulty output with -0.9999..., but with no other number/format combination I have tried.
I get normal output (i.e. all 1.) with other compilers on other machines, such as gcc-g77-3.2.2-5 on i686; moreover (if that's relevant)

#include <stdio.h>
int main()
{
  printf("%3.0f\n",0.999);
  printf("%3.0f\n",0.9999);
  printf("%3.0f\n",0.99999);
  printf("%3.0f\n",0.999999);
  printf("%3.0f\n",0.9999999);
  printf("%3.0f\n",0.99999999);
}

gives all ones too, when compiled on the same machine with gcc-4.1.1-1.fc5
Comment 1 Andrew Pinski 2006-07-12 08:56:48 UTC
0.99999 in Fortran is 0.99999f in C.
Comment 2 Francois-Xavier Coudert 2006-07-12 15:21:52 UTC
Confirmed, and not target-specific. I'll look into it.
Comment 3 Francois-Xavier Coudert 2006-08-21 11:26:32 UTC
OK, right, I don't have time to fix this. I've looked at the rounding code, and carry propagation, and I think we'd need a new special case to handle that, but couldn't find a way to do it that doesn't break other cases.

Jerry, Thomas, could you look into this? I find it has a pretty high annoyance factor, we're outputing wrong numbers.
Comment 4 Jerry DeLisle 2006-08-22 00:25:42 UTC
I will take this on,
Comment 5 Jerry DeLisle 2006-08-28 05:14:15 UTC
Subject: Bug 28354

Author: jvdelisle
Date: Mon Aug 28 05:14:05 2006
New Revision: 116502

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116502
Log:
2006-08-27  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/28354
	* io/write.c: Check for special case of zero precision in format
	and pre-round the real value.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/write.c

Comment 6 Jerry DeLisle 2006-08-28 05:17:14 UTC
Subject: Bug 28354

Author: jvdelisle
Date: Mon Aug 28 05:17:09 2006
New Revision: 116503

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116503
Log:
2006-08-27  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/28354
	* gfortran.dg/fmt_zero_precision.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/fmt_zero_precision.f90
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 7 Jerry DeLisle 2006-08-28 05:18:42 UTC
Fixed on 4.2
Comment 8 Andrew Pinski 2006-08-30 15:47:55 UTC
Fixed so closing as such.
Comment 9 Martin Michlmayr 2007-04-28 11:42:33 UTC
Still a problem with 4.1.  Will this be backported?
Comment 10 Jerry DeLisle 2007-04-28 16:31:29 UTC
We are so close to a 4.2 release I think we may see 4.2 out before the next cycle, if any on 4.1.  If you are able to build your own version of gfortran, I would suggest move to 4.2 yourself or even 4.3.  Also check the gfortran wiki for more up to date binaries.  I don't know what platform you are using.  So probably no.

Let me know if you need help getting a more recent build.