bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Comparing a double against 0


From: Julián Albo
Subject: Comparing a double against 0
Date: Wed, 02 Jul 2003 20:16:52 +0200

Hello.

I have the following program:

#include <stdio.h>
#include <math.h>

const double zero= 0.0;

int main ()
{
        double a= -1.0e-120;
        if (a < zero)
                printf ("%g < 0\n", a);
        if (a > zero)
                printf ("%g > 0\n", a);
        if (a == zero)
                printf ("%g == 0\n", a);
}

Compiled as C++ with gcc version 3.3 20030226 (prerelease) (SuSE Linux)

The ouput is -1e-120 == 0.

Dropping the const in zero the output is: -1e-120 < 0, as expected.

Compiled as C program the result is correct with and without const.

Using the literal 0.0 instead of the zero variable, the result is wrong
with C++ and correct with C.

Is this a known bug?

Regards.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]