Subject: Re: Maths ruined when optimizing in gcc
From: [email-masked]

26 Nov 1996 14:45:12 -0800
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Original-To: [email-masked]
Original-CC: [email-masked], [email-masked]
Original-Sender: [email-masked]

Hi Mumit, you wrote:

: Another data point here. I'm in the process of testing g77 port to
: cygwin32 (it was quite simple once I figured out the right flags to
: libfI77) and the big gotcha is the every time I use -O, some of the
: programs produce NaNs all over the place! Haven't been able to pin
: point where it happens yet, but hopefully soon.
:
: Anybody have a short program that screws up the numerics with -O? If
: so, please email it me (if fortran, then either original or f2c'd will
: do fine).

Yes, here it is:

--- snip here ---
#include <stdio.h>
int main(argc, argv)
int argc;
char *argv[];
{
        volatile char c = 10;
        volatile int i = c;
        float x = c / 5.0, y = i / 5.0;
        printf("%.2f %.2f\n", x, y);
        return 0;
}
--- snip here ---

with the following results:

--- snip here ---
bash$ gcc floatbug.c -o floatbug.exe
bash$  floatbug
2.00 2.00
bash$ gcc -O floatbug.c -o floatbug.exe
bash$ floatbug
Inf Inf
bash$
--- snip here ---

This is stripped down from my big program which also produced NaNs.
The original doesn't use volatile, but that prevents compile time evaluation.
Astonishingly this shows Inf (using b16), which is not any better!

BTW, I just joined the mailinglist, so I missed the start of the thread.

Bye, Heribert ([email-masked])
-
For help on using this list, send a message to
"[email-masked]" with one line of text: "help".