public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* floating point exception flags and compiler optimization
@ 2006-09-22  9:09 Richard B. Kreckel
  0 siblings, 0 replies; only message in thread
From: Richard B. Kreckel @ 2006-09-22  9:09 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1056 bytes --]

Hi,

I just tried playing with the floating point exceptions using the
<fenv.h> functionality defined in C99. However, it seems to interfere
somehow with optimization. Can anyone give a hint what's going on?
Here is my test program:

$ cat fenv.c
#include <fenv.h>
#include <stdio.h>

int main()
{
    // disguise constants one and zero, in order to fool the compiler
    double x = (double)printf("") + 1.0; // one
    double y = (double)printf(""); // zero
    if (fetestexcept(FE_ALL_EXCEPT)) {
        printf("flag set before call.\n");
    }
    double z = x / y;
    if (fetestexcept(FE_ALL_EXCEPT)) {
        printf("flag set after call.\n");
    }
    printf("%f/%f==%f\n",x,y,z);

}
$ gcc -O0 fenv.c -lm && ./a.out
flag set after call.
1.000000/0.000000==inf
$ gcc -O1 fenv.c -lm && ./a.out
1.000000/0.000000==inf

I also found that the behavior appears to depend on the compiler
version used. gcc 3.x and 4.0 print "flat set after call." even with
optimization, but the above is gcc 4.1.

TIA
  -richy.
-- 
Richard B. Kreckel
<kreckel@ginac.de>


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/x-pkcs7-signature, Size: 3204 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-09-22  9:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-22  9:09 floating point exception flags and compiler optimization Richard B. Kreckel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).