This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Strange g+ 3.1.1 double behavior
- From: Gunther Weber <weber at informatik dot uni-kl dot de>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 05 Aug 2002 16:06:14 +0200
- Subject: Strange g+ 3.1.1 double behavior
Hello,
while searching for a problem in one of my programs I ran across this
strange gcc 3.1.1 beahvior:
--- TestFloat.cc ---
#include <iostream>
double torus(double x, double y, double z)
{
const double R = .7;
const double r = .1;
return (x*x + y*y)*(x*x + y*y) - 2*(R*R + (r*r - z*z))*(x*x + y*y) +
(R*R - (r*r - z*z))*(R*R - (r*r - z*z));
}
int main()
{
std::cout << torus(0.0,0.0,10.0) - torus(0.0,0.0,10.0) << std::endl;
}
--- Test Float.cc ---
--- Log ---.
[weber@stella Test]$ g++3.1.1 TestFloat.cc
-Wl,--rpath,/usr/global/packages/languages/gcc-3.1.1/lib
[weber@stella Test]$ ./a.out
3.85469e-13
[weber@stella Test]$ g++3.1.1 --version
g++3.1.1 (GCC) 3.1.1
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
gcc3.1.1 -v
Reading specs from
/usr/global/packages/languages/gcc-3.1.1/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/specs
Configured with: ./configure
--prefix=/usr/global/packages/languages/gcc-3.1.1 --enable-languages=c,c++
Thread model: single
gcc version 3.1.1
[weber@stella Test]$ ldd a.out
libstdc++.so.4 =>
/usr/global/packages/languages/gcc-3.1.1/lib/libstdc++.so.4 (0x40014000)
libm.so.6 => /lib/i686/libm.so.6 (0x400d4000)
libgcc_s.so.1 =>
/usr/global/packages/languages/gcc-3.1.1/lib/libgcc_s.so.1 (0x400f6000)
libc.so.6 => /lib/i686/libc.so.6 (0x42000000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
--- Log ---
All this on a Celeron system running RedHat 7.3. Does anyone what could
be causing this? I would expect that both function calls with identical
arguments would result in the same double value and thus in the programm
printing "0".
Thank you for any help
Gunther H Weber