Hi,
I hope this has not been addressed before but my search returned nothing
the same. I found vaguely related stuff but not this.
I am talking is straightforward optimization, i.e. -O3 (say), which I read
the manual page to say, does not affect IEEE 754 stuff at all.
The following code
#include <fenv.h>
#include <stdio.h>
int bug()
{
double z;
int test;
feclearexcept(FE_ALL_EXCEPT);
printf("Except %x\n", fetestexcept(FE_ALL_EXCEPT));
z = 1.0 - Tiny;
test = fetestexcept(FE_ALL_EXCEPT);
printf("TEST says %x @%.9e should be %x\n", test, z, FE_INEXACT);
return(0);
}
int main()
{
bug();
return(0);
}
When compiled as just
gcc bug.c -lm
correctly raised the FP_INEXACT (0x20) flag. It produces
Except 0
TEST says 20 @1.000000000e+00 should be 20
where the first line notes that it starts cleared.
When compiled as
gcc -O3 bug.c -lm
or even
g++ bug.c
The second line produced says
TEST says 0 @1.000000000e+00 should be 20
There is no exception raised.
What did I do wrong. The -O flags is not supposed to affect that.
Does it need some extra flag? Do I need a much newer version?
The version is 4.8.5-16 (on CentOS 7.4)
Thanks - Damian
Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer