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
0.99999 in Fortran is 0.99999f in C.
Confirmed, and not target-specific. I'll look into it.
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.
I will take this on,
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
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
Fixed on 4.2
Fixed so closing as such.
Still a problem with 4.1. Will this be backported?
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.