[Bug target/12639] long double comparison is broken
--- Comment #3 from christopher dot eltschka at physik dot uni-regensburg dot de 2005-10-27 09:11 --- I just stumbled on the same problem, but with much more conventional numbers. The following C++ test program demonstrates it: #include // this just serves to calculate a positive number which the optimizer // will not figure out at compile time long double f() { long double value = 1.0; for (int i = 0; i < 10; ++i) value += (long double)i; return value; } int main() { long double a = f(); std::cout << a; if (a > 0) std::cout << " > 0\n"; else if (a < 0) std::cout << " < 0\n"; else if (a == 0) std::cout << " == 0\n"; else std::cout << "oops!\n"; } Compiling and running gives: > g++ longdouble.cc -O3 && a.out 46 == 0 which is clearly wrong. The same result happens with -O2 and -O1. With -O0 I correctly get the output 46 > 0. The compiler is: > g++ -v Reading specs from /usr/local/lib/gcc-lib/alphaev67-dec-osf5.1/3.3/specs Configured with: ../gcc-3.3/configure --with-libiconv-prefix=/usr/local --with-included-gettext Thread model: single gcc version 3.3 As workaround for == 0, !! seems to work. Unfortunately I don't know a workaround for > 0 and < 0. -- christopher dot eltschka at physik dot uni-regensburg dot de changed: What|Removed |Added CC||christopher dot eltschka at ||physik dot uni-regensburg ||dot de http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12639
[Bug target/12639] long double comparison is broken
--- Comment #4 from christopher dot eltschka at physik dot uni-regensburg dot de 2005-10-27 10:38 --- (In reply to comment #3) > As workaround for == 0, !! seems to work. Unfortunately I don't know a > workaround for > 0 and < 0. > Sorry for self-reply, but now I've found a simple workaround for all cases: Instead of comparing with 0, just add 1 and compare with 1. For some reason this works even if the number to compare with happens to be -1 (i.e. if after adding 1 you get 0). -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12639
[Bug target/12639] long double comparison is broken
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12639 Serge Belyshev changed: What|Removed |Added Keywords||wrong-code Status|REOPENED|RESOLVED CC||belyshev at depni dot ||sinp.msu.ru Known to work||4.2.4, 4.3.5, 4.4.5, 4.5.2 Resolution||FIXED Severity|critical|normal --- Comment #5 from Serge Belyshev 2011-03-05 18:37:52 UTC --- Works on ev56 and ev67 linux-gnu with gcc 4.2 .. 4.5, assuming fixed.