public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version)
       [not found] <20030521102600.11431.qmail@sources.redhat.com>
@ 2003-05-21 11:36 ` Jos van den Oever
  2003-05-21 12:39 ` Jos van den Oever
  2003-05-21 12:58 ` Jos van den Oever
  2 siblings, 0 replies; 9+ messages in thread
From: Jos van den Oever @ 2003-05-21 11:36 UTC (permalink / raw)
  To: gcc-bugs

Just a small addition to the bug report.

Compiling with -ffloat-store does not alleviate the problem.

This problem is not a problem of too much precision, but one of too little 
precision.

The following comparison is true in gcc 3.3 (SuSE prerelease):

double(1) == double(1) - 134217728*DBL_EPSILON

According to the definition in <cfloat>, DBL_EPSILON is the smallest number 
for which 1 - DBL_EPSILON != 1.


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

* Re: c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version)
       [not found] <20030521102600.11431.qmail@sources.redhat.com>
  2003-05-21 11:36 ` c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version) Jos van den Oever
@ 2003-05-21 12:39 ` Jos van den Oever
  2003-05-21 12:58 ` Jos van den Oever
  2 siblings, 0 replies; 9+ messages in thread
From: Jos van den Oever @ 2003-05-21 12:39 UTC (permalink / raw)
  To: gcc-bugs

Another addition to the report.
Comparing doubles in c does work properly:

#include <stdio.h>
#include <float.h>

int
main() {
        double one = 1.0;
        double belowone = 1.0-DBL_EPSILON;

        if (one == belowone) {
                printf("one == belowone\n");
        } else {
                printf("one != belowone\n");
        }

        if (1.0 == 1.0 - DBL_EPSILON) {
                printf("1.0 == 1.0 - DBL_EPSILON\n");
        } else {
                printf("1.0 != 1.0 - DBL_EPSILON\n");
        }
        return 0;
}

gives output:

one != belowone
1.0 != 1.0 - DBL_EPSILON

which is what you'd expect.


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

* Re: c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version)
       [not found] <20030521102600.11431.qmail@sources.redhat.com>
  2003-05-21 11:36 ` c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version) Jos van den Oever
  2003-05-21 12:39 ` Jos van den Oever
@ 2003-05-21 12:58 ` Jos van den Oever
  2 siblings, 0 replies; 9+ messages in thread
From: Jos van den Oever @ 2003-05-21 12:58 UTC (permalink / raw)
  To: gcc-gnats, nobody, gcc-bugs

More info:

The bug is not present in gcc version 3.2 (Mandrake Linux 9.0 3.2-1mdk).



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

* Re: c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version)
  2003-05-21 15:00   ` Wolfgang Bangerth
  2003-05-21 15:59     ` Jos van den Oever
@ 2003-05-21 18:43     ` Jos van den Oever
  1 sibling, 0 replies; 9+ messages in thread
From: Jos van den Oever @ 2003-05-21 18:43 UTC (permalink / raw)
  To: Wolfgang Bangerth; +Cc: gcc-bugs, gcc-gnats

On Wednesday 21 May 2003 16:41, Wolfgang Bangerth wrote:
> If you use
>   ../gcc-3.3/configure --prefix=/some/local/path
>   make bootstrap
>   make install
> it will install gcc into /some/local/path, which could be a scratch
> directory in your homedir, or in /tmp. It won't overwrite any preinstalled
> files in /usr/... That's a safe way not to compromise the integrity of a
> production system. You can then run the compiler by setting PATH and
> LD_LIBRARY_PATH just for once in a shell window.

I compiled gcc thus:

../gcc-3.3/configure --prefix=/tmp/testgcc
make bootstrap; make install
export PATH=/tmp/testgcc/bin:$PATH
export LD_LIBRARY_PATH=/tmp/testgcc/lib:$LD_LIBRARY_PATH
g++ -O2     testgcc2.cpp   -o testgcc2

and the bug was not present in the gcc3.3 release. Not even when run on SuSE 
8.2. And the bug is also present on my old laptop, also with SuSE 8.2.
So the problem is really in SuSE's snapshot of gcc.

I guess the gcc team is off the hook. :-)

Best regards and thanks for the help!

Jos van den Oever




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

* Re: c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version)
  2003-05-21 15:00   ` Wolfgang Bangerth
@ 2003-05-21 15:59     ` Jos van den Oever
  2003-05-21 18:43     ` Jos van den Oever
  1 sibling, 0 replies; 9+ messages in thread
From: Jos van den Oever @ 2003-05-21 15:59 UTC (permalink / raw)
  To: Wolfgang Bangerth; +Cc: gcc-bugs, gcc-gnats

On Wednesday 21 May 2003 16:41, you wrote:
> If you use
>   ../gcc-3.3/configure --prefix=/some/local/path
>   make bootstrap
>   make install
> it will install gcc into /some/local/path, which could be a scratch
> directory in your homedir, or in /tmp. It won't overwrite any preinstalled
> files in /usr/... That's a safe way not to compromise the integrity of a
> production system. You can then run the compiler by setting PATH and
> LD_LIBRARY_PATH just for once in a shell window.

Ok, thanks for the instruction. It sounds safe to me, so I'll try it.


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

* Re: c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version)
  2003-05-21 14:54 ` Jos van den Oever
@ 2003-05-21 15:00   ` Wolfgang Bangerth
  2003-05-21 15:59     ` Jos van den Oever
  2003-05-21 18:43     ` Jos van den Oever
  0 siblings, 2 replies; 9+ messages in thread
From: Wolfgang Bangerth @ 2003-05-21 15:00 UTC (permalink / raw)
  To: Jos van den Oever; +Cc: gcc-bugs, gcc-gnats


> I'd like to install the released version of gcc 3.3, but as this is a 
> production system I'm working on, I prefer to install rpms from SuSE.

If you use
  ../gcc-3.3/configure --prefix=/some/local/path
  make bootstrap
  make install
it will install gcc into /some/local/path, which could be a scratch 
directory in your homedir, or in /tmp. It won't overwrite any preinstalled 
files in /usr/... That's a safe way not to compromise the integrity of a 
production system. You can then run the compiler by setting PATH and 
LD_LIBRARY_PATH just for once in a shell window.


> If there are any (SuSE or other reliable) rpms with gcc 3.3 I'm willing to 
> test.

I have no clue. I'd think that SuSE might have one, but don't know.

W.

-------------------------------------------------------------------------
Wolfgang Bangerth              email:            bangerth@ices.utexas.edu
                               www: http://www.ices.utexas.edu/~bangerth/



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

* Re: c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version)
  2003-05-21 14:35 bangerth
@ 2003-05-21 14:54 ` Jos van den Oever
  2003-05-21 15:00   ` Wolfgang Bangerth
  0 siblings, 1 reply; 9+ messages in thread
From: Jos van den Oever @ 2003-05-21 14:54 UTC (permalink / raw)
  To: bangerth, gcc-bugs, gcc-prs, nobody, gcc-gnats

On Wednesday 21 May 2003 16:14, bangerth@dealii.org wrote:
> Synopsis: comparing doubles is not consistent in gcc 3.3 (SuSE version)
>
> State-Changed-From-To: open->feedback
> State-Changed-By: bangerth
> State-Changed-When: Wed May 21 14:14:07 2003
> State-Changed-Why:
>     I get the same result for 3.2.3, 3.3 (release) and 3.4
>     (mainline):
>
>     g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ x.cc
>     g/x> ./a.out
>     one != belowone
>     double(1) != double(1) - DBL_EPSILON
>
>     Could you possibly try with the 3.3 release, not with the
>     snapshot SuSE is shipping?

I'm very glad to hear the bug is not present in the systems you tested.
I'd like to install the released version of gcc 3.3, but as this is a 
production system I'm working on, I prefer to install rpms from SuSE.
I do have an old laptop at home, but it's not capable of compiling gcc in a 
finite time.

If there are any (SuSE or other reliable) rpms with gcc 3.3 I'm willing to 
test.


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

* Re: c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version)
@ 2003-05-21 14:35 bangerth
  2003-05-21 14:54 ` Jos van den Oever
  0 siblings, 1 reply; 9+ messages in thread
From: bangerth @ 2003-05-21 14:35 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, jos, nobody

Synopsis: comparing doubles is not consistent in gcc 3.3 (SuSE version)

State-Changed-From-To: open->feedback
State-Changed-By: bangerth
State-Changed-When: Wed May 21 14:14:07 2003
State-Changed-Why:
    I get the same result for 3.2.3, 3.3 (release) and 3.4
    (mainline):
    
    g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ x.cc
    g/x> ./a.out
    one != belowone
    double(1) != double(1) - DBL_EPSILON
    
    Could you possibly try with the 3.3 release, not with the
    snapshot SuSE is shipping?
    
    Thanks
      Wolfgang

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10902


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

* c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version)
@ 2003-05-21 11:23 jos
  0 siblings, 0 replies; 9+ messages in thread
From: jos @ 2003-05-21 11:23 UTC (permalink / raw)
  To: gcc-gnats


>Number:         10902
>Category:       c++
>Synopsis:       comparing doubles is not consistent in gcc 3.3 (SuSE version)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Wed May 21 10:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     jos@vandenoever.info
>Release:        unknown-1.0
>Organization:
>Environment:
SuSE 8.2 i386
>Description:
When comparing doubles without storing them in a temporary variable, the comparison can go wrong. The code below compares two doubles. One of them has value 1, the other has the value of the largest value below 1. When comparing these numbers, the difference is found.
But when comparing these numbers without storing the result, the comparison is apparently performed in float precision.

#include <iostream>
using std::cout;
using std::endl;
#include <cfloat>

int
main() {
        double one = double(1);
        double belowone = double(1)-DBL_EPSILON;

        if (one == belowone) {
                cout << "one == belowone" << endl;
        } else {
                cout << "one != belowone" << endl;
        }

        if (double(1) == double(1) - DBL_EPSILON) {
                cout << "double(1) == double(1) - DBL_EPSILON" << endl;
                int i=1;
                while (double(1) == double(1) - i*DBL_EPSILON) ++i;
                cout << "double(1) == double(1) - "<<i-1<<"*DBL_EPSILON"
                        << endl;
                cout << "This comparison is not OK!" << endl;

        } else {
                cout << "double(1) != double(1) - DBL_EPSILON" << endl;
        }

        return 0;
}
>How-To-Repeat:
Compile the code given above. I find the bug with gcc version 3.3 20030226 (prerelease) (SuSE Linux), irrespective of using -O or -g.

When using gcc version 2.95.3 20010315 (SuSE), the bug is not present.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2003-05-21 18:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20030521102600.11431.qmail@sources.redhat.com>
2003-05-21 11:36 ` c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version) Jos van den Oever
2003-05-21 12:39 ` Jos van den Oever
2003-05-21 12:58 ` Jos van den Oever
2003-05-21 14:35 bangerth
2003-05-21 14:54 ` Jos van den Oever
2003-05-21 15:00   ` Wolfgang Bangerth
2003-05-21 15:59     ` Jos van den Oever
2003-05-21 18:43     ` Jos van den Oever
  -- strict thread matches above, loose matches on Subject: below --
2003-05-21 11:23 jos

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