A C program, compiled without optimization, which does repeated multiplications by 10 on a float number (0.2008) outputs incorrect results. I know about the "most often reported non-bug", but since the K&R specifies that FLT_DIG (decimal digits of precision) must be at least 6, I still consider this to be a possible bug. The program was compiled with command line: 'gcc --save-temps ~/mathbug.c' -----BEGIN PROGRAM OUTPUT----- nn = 2.008000 nn = 20.079998 nn = 200.799988 nn = 2007.999878 nn = 20079.998047 nn = 200799.984375 nn = 2007999.875000 ------END PROGRAM OUTPUT------ -----BEGIN VERSION INFO----- ~> gcc -v Using built-in specs. Target: i386-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux Thread model: posix gcc version 4.1.2 20070626 (Red Hat 4.1.2-14) ~> uname -a Linux xyzzy.local 2.6.18-92.1.6.el5 #1 SMP Wed Jun 25 12:46:39 EDT 2008 i686 athlon i386 GNU/Linux ------END VERSION INFO------
Created attachment 15860 [details] The program's source code
Created attachment 15861 [details] The preprocessed source
Why do you think the results are incorrect? Did you hear aboud round-off errors? 0.2008 cannot be represented exactly in float (nor in double) and you cannot expect to have more that six significant digits. If you want to get what you expect, use the right format for the output (not fluent enough in C to give it to you).
Not a bug.
(In reply to comment #4) Well it certainly gives wrong results.
(In reply to comment #5) > Well it certainly gives wrong results. No! Read comment #3 and learn the primers about floating point numbers.
You should also read http://www.validlab.com/goldberg/paper.pdf . >Well it certainly gives wrong results. In this case, the number is not directly representable in float. You will be able to get better precision with double but it will still not be directly representable.