S
Szabolcs Nagy
hello, i get unexpected floating point behaviour
the following code prints "not eq" on various compilers with various
settings on my 32bit x86 machine:
#include <stdlib.h>
#include <stdio.h>
int main() {
if ((double)atoi("1")/atoi("3") == (double)atoi("1")/atoi
("3"))
puts("eq");
else
puts("not eq");
return 0;
}
with gcc it seems the first division is performed with x86 80bit float
registers but the second division is done with a different instruction
which i don't know exactly
i know floating point equality check is rarely adequate and there are
rounding errors etc.
but does the standard allow such behaviour in this case?
ie. is it a compiler bug or 'undefined behaviour'?
the following code prints "not eq" on various compilers with various
settings on my 32bit x86 machine:
#include <stdlib.h>
#include <stdio.h>
int main() {
if ((double)atoi("1")/atoi("3") == (double)atoi("1")/atoi
("3"))
puts("eq");
else
puts("not eq");
return 0;
}
with gcc it seems the first division is performed with x86 80bit float
registers but the second division is done with a different instruction
which i don't know exactly
i know floating point equality check is rarely adequate and there are
rounding errors etc.
but does the standard allow such behaviour in this case?
ie. is it a compiler bug or 'undefined behaviour'?