This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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 <iostream>

// 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]