public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/36737]  New: Wrong results from floating-point multiplication by 10
@ 2008-07-05  9:11 aremo at ngi dot it
  2008-07-05  9:12 ` [Bug c/36737] " aremo at ngi dot it
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: aremo at ngi dot it @ 2008-07-05  9:11 UTC (permalink / raw)
  To: gcc-bugs

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------


-- 
           Summary: Wrong results from floating-point multiplication by 10
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: aremo at ngi dot it
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36737


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/36737] Wrong results from floating-point multiplication by 10
  2008-07-05  9:11 [Bug c/36737] New: Wrong results from floating-point multiplication by 10 aremo at ngi dot it
@ 2008-07-05  9:12 ` aremo at ngi dot it
  2008-07-05  9:15 ` aremo at ngi dot it
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: aremo at ngi dot it @ 2008-07-05  9:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from aremo at ngi dot it  2008-07-05 09:12 -------
Created an attachment (id=15860)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15860&action=view)
The program's source code


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36737


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/36737] Wrong results from floating-point multiplication by 10
  2008-07-05  9:11 [Bug c/36737] New: Wrong results from floating-point multiplication by 10 aremo at ngi dot it
  2008-07-05  9:12 ` [Bug c/36737] " aremo at ngi dot it
@ 2008-07-05  9:15 ` aremo at ngi dot it
  2008-07-05  9:49 ` dominiq at lps dot ens dot fr
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: aremo at ngi dot it @ 2008-07-05  9:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from aremo at ngi dot it  2008-07-05 09:14 -------
Created an attachment (id=15861)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15861&action=view)
The preprocessed source


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36737


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/36737] Wrong results from floating-point multiplication by 10
  2008-07-05  9:11 [Bug c/36737] New: Wrong results from floating-point multiplication by 10 aremo at ngi dot it
  2008-07-05  9:12 ` [Bug c/36737] " aremo at ngi dot it
  2008-07-05  9:15 ` aremo at ngi dot it
@ 2008-07-05  9:49 ` dominiq at lps dot ens dot fr
  2008-07-05  9:54 ` schwab at suse dot de
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: dominiq at lps dot ens dot fr @ 2008-07-05  9:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from dominiq at lps dot ens dot fr  2008-07-05 09:48 -------
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).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36737


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/36737] Wrong results from floating-point multiplication by 10
  2008-07-05  9:11 [Bug c/36737] New: Wrong results from floating-point multiplication by 10 aremo at ngi dot it
                   ` (2 preceding siblings ...)
  2008-07-05  9:49 ` dominiq at lps dot ens dot fr
@ 2008-07-05  9:54 ` schwab at suse dot de
  2008-07-05 10:07 ` aremo at ngi dot it
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: schwab at suse dot de @ 2008-07-05  9:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from schwab at suse dot de  2008-07-05 09:54 -------
Not a bug.


-- 

schwab at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36737


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/36737] Wrong results from floating-point multiplication by 10
  2008-07-05  9:11 [Bug c/36737] New: Wrong results from floating-point multiplication by 10 aremo at ngi dot it
                   ` (3 preceding siblings ...)
  2008-07-05  9:54 ` schwab at suse dot de
@ 2008-07-05 10:07 ` aremo at ngi dot it
  2008-07-05 10:17 ` dominiq at lps dot ens dot fr
  2008-07-05 19:08 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: aremo at ngi dot it @ 2008-07-05 10:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from aremo at ngi dot it  2008-07-05 10:06 -------
(In reply to comment #4)

Well it certainly gives wrong results.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36737


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/36737] Wrong results from floating-point multiplication by 10
  2008-07-05  9:11 [Bug c/36737] New: Wrong results from floating-point multiplication by 10 aremo at ngi dot it
                   ` (4 preceding siblings ...)
  2008-07-05 10:07 ` aremo at ngi dot it
@ 2008-07-05 10:17 ` dominiq at lps dot ens dot fr
  2008-07-05 19:08 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: dominiq at lps dot ens dot fr @ 2008-07-05 10:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from dominiq at lps dot ens dot fr  2008-07-05 10:16 -------
(In reply to comment #5)

> Well it certainly gives wrong results.

No! Read comment #3 and learn the primers about floating point numbers.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36737


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/36737] Wrong results from floating-point multiplication by 10
  2008-07-05  9:11 [Bug c/36737] New: Wrong results from floating-point multiplication by 10 aremo at ngi dot it
                   ` (5 preceding siblings ...)
  2008-07-05 10:17 ` dominiq at lps dot ens dot fr
@ 2008-07-05 19:08 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-07-05 19:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from pinskia at gcc dot gnu dot org  2008-07-05 19:08 -------
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.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36737


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-07-05 19:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-05  9:11 [Bug c/36737] New: Wrong results from floating-point multiplication by 10 aremo at ngi dot it
2008-07-05  9:12 ` [Bug c/36737] " aremo at ngi dot it
2008-07-05  9:15 ` aremo at ngi dot it
2008-07-05  9:49 ` dominiq at lps dot ens dot fr
2008-07-05  9:54 ` schwab at suse dot de
2008-07-05 10:07 ` aremo at ngi dot it
2008-07-05 10:17 ` dominiq at lps dot ens dot fr
2008-07-05 19:08 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).