[Bug c/45691] Floating point comparison failure

2010-09-16 Thread dominiq at lps dot ens dot fr


--- Comment #1 from dominiq at lps dot ens dot fr  2010-09-16 17:02 ---
pr323?

As a general rule: never compare floating points for equality, use
abs(a-b)epsilon.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45691



[Bug c/45691] Floating point comparison failure

2010-09-16 Thread paolo dot carlini at oracle dot com


--- Comment #2 from paolo dot carlini at oracle dot com  2010-09-16 17:08 
---
As an even more general rule, remember to always specify your target: in this
case, for example, I can't reproduce at all the behavior on x86_64 -m64, only
with -m32.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45691



[Bug c/45691] Floating point comparison failure

2010-09-16 Thread pinskia at gcc dot gnu dot org


--- Comment #3 from pinskia at gcc dot gnu dot org  2010-09-16 17:08 ---


*** This bug has been marked as a duplicate of 323 ***

*** This bug has been marked as a duplicate of 323 ***


-- 

pinskia at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45691



[Bug c/45691] Floating point comparison failure

2010-09-16 Thread jakub at gcc dot gnu dot org


--- Comment #4 from jakub at gcc dot gnu dot org  2010-09-16 17:13 ---
i?86 is a FLT_EVAL_METHOD 2 target, so for strict C compliance all floating
operations and constants are supposed to be evaluated in the precision
of long double.  The assignment of the constant to a double var or explicit
cast to double cause rounding to happen, so your testcase is evaluated as:
  int main()
  {
  double z = 3.14159265358979323846L;
  puts((long double) z == 3.14159265358979323846L ? == : !=);
  return 0;
  }
and of course (double) 3.14159265358979323846L != 3.14159265358979323846L.
You can use -fexcess-precision=fast (the default unless -std=c99/-std=c89
is requested) for the old behavior, or you can add explicit cast,
z == (double) M_PI, or (as usually a good idea) avoid floating point
equality/non-equality comparisons, instead check whether difference is
smaller than some epsilon. 


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45691



[Bug c/45691] Floating point comparison failure

2010-09-16 Thread paolo dot carlini at oracle dot com


--- Comment #5 from paolo dot carlini at oracle dot com  2010-09-16 17:15 
---
Thanks Jakub.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45691



[Bug c/45691] Floating point comparison failure

2010-09-16 Thread ian at macky dot net


--- Comment #6 from ian at macky dot net  2010-09-16 17:44 ---
Subject: Re:  Floating point comparison failure

Thanks everyone.  I usually do fuzzy floating-point comparison, except in
certain special circumstances.  I will switch to using double constants;
I'm trying for a code that is maximally portable, so having to worry about
what exact compiler switches to use is anathema.

And might I add: you people are super-fast!  I'm very impressed.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45691