[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Bug rtl-optimization/323] optimized code gives strange floating point results




------- Comment #130 from nszabolcs at gmail dot com  2009-07-22 12:10 -------
(In reply to comment #129)
> I am a bit wondering if this bug is also for the case (a < b) && (b < a) ==
> true. Is it?

i guess so, see:

#include <stdlib.h> 
#include <stdio.h> 

#define axiom_order(a,b)  !(a < b && b < a) 
#define axiom_eq(a)       a == a 
#define third             ((double)atoi("1")/atoi("3"))

int main(void) {
        if (axiom_order(third, third))
                puts("ok");
        else
                puts("error");

        if (axiom_eq(third))
                puts("ok");
        else
                puts("error");

        return 0;
}


here this prints
error
error
with gcc 4.2 and -S shows that this is long double vs double precision problem


> Because if so, this becomes way more serious, as for example std::set<double>
> is broken then (and depending on the STL implementation, it will throw
> assertions then).

in C99 (+TC1,TC2,TC3) different precision is not allowed

5.1.2.3 p12:
  ... In particular, casts and assignments are required to perform their
specified conversion

5.2.4.2.2 p8:
  Except for assignment and cast (which remove all extra range and precision),
the values 8 of operations with floating operands and values subject to the
usual arithmetic conversions and of floating constants are evaluated to a
format whose range and precision may be greater than required by the type.

i'm not sure about c++ though


-- 


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

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Reply to: