This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
egcs 1.0.3 bug in comparing doubles
- To: egcs-bugs at cygnus dot com
- Subject: egcs 1.0.3 bug in comparing doubles
- From: Olaf Lenzmann <lenzmann at bned dot com>
- Date: Thu, 27 Aug 1998 19:47:14 +0200
- Organization: BNeD GmbH
Hello!
I encountered the following SEVERE bug w/ egcs (gcc version egcs-2.90.29
980515) on Linux
RedHat5.1. When compiling the attached source with "gcc mtest.cc -lm
-lstdc++" the result of
the first comparison is falsely considered false.
Olaf Lenzmann
--
B N e D --- Speedup Phot o n i c s
http://www.BNeD.com Phone: +49-30-34704715
mailto: lenzmann@BNeD.com Fax : +49-30-34704717
#include <stdio.h>
#include <math.h>
#include <iostream.h>
double snapToGrid(double value, double atomic)
{
if( atomic == 0.0 )
return value;
double remainder = fmod(value, atomic);
// Which direction?
if(remainder < 0.5*atomic)
return value - remainder;
else
return value + atomic - remainder;
}
int main (void) {
double a = 6.375e-10;
double b = 6.375e-10;
double grid = 1.25e-11;
if( snapToGrid(a, grid) == snapToGrid(b, grid) )
cout << "Function calls yield equal result" << endl;
double aResult = snapToGrid(a, grid);
double bResult = snapToGrid(b, grid);
if( aResult == bResult )
cout << "Variables yield equal result" << endl;
}