From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25219 invoked by alias); 21 May 2003 10:33:09 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 11434 invoked by uid 71); 21 May 2003 10:26:00 -0000 Resent-Date: 21 May 2003 10:26:00 -0000 Resent-Message-ID: <20030521102600.11433.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, jos@vandenoever.info Received: (qmail 28974 invoked by uid 48); 21 May 2003 10:18:16 -0000 Message-Id: <20030521101816.28973.qmail@sources.redhat.com> Date: Wed, 21 May 2003 10:33:00 -0000 From: jos@vandenoever.info Reply-To: jos@vandenoever.info To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c++/10902: comparing doubles is not consistent in gcc 3.3 (SuSE version) X-SW-Source: 2003-05/txt/msg02281.txt.bz2 List-Id: >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 using std::cout; using std::endl; #include 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) - "<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: