[patch, testsuite] Fix PR37334 - gcc.dg/fastmath-2.c doesn't work on ia32
Victor Kaplansky
VICTORK@il.ibm.com
Thu Sep 4 00:58:00 GMT 2008
Janis Johnson <janis187@us.ibm.com> wrote on 03/09/2008 20:08:39:
> Why is a test using -ffast-math expecting an exact comparison
> of a floating-point calculation?
>
> Janis
>
"-ffast-math" was used in order to turn on "-ffinite-math-only", and
probably it was bad idea to use it. I actually intended to use
-ffinite-math-only.
But, the following example aborts even without "-ffast-math" flag:
=======================================
extern void abort (void);
volatile double a = 2.002083e-146;
double b;
int
main()
{
b = 1. / a;
if (b != (1. / 2.002083e-146))
abort ();.
return 0;);.
}
=======================================
% gcc -O -lm -m32 t.c && ./a.out
Aborted
%
However, if "b" is defined as volatile, forcing the result of division
to be propagated through a memory, the test doesn't abort even
with "--fast-math":
=======================================
extern void abort (void);
volatile double a = 2.002083e-146;
volatile double b;
int
main()
{
b = 1. / a;
if (b != (1. / 2.002083e-146))
abort ();.
return 0;);.
}
=======================================
% gcc -O -ffast-math -lm -m32 t.c && ./a.out
%
According to the documentation, "-ffinite-math-only" allows optimizations
for
floating-point arithmetic that assume that arguments and results are not
NaNs or +-Infs. In case above, both "2.002083e-146" and "1 /
2.002083e-146"
are finite numbers (not NaNs or +-Infs), so I assume that result of
division
should be accurate even with "-ffinite-math-only".
Thus, I need a help to create a test, which will check an accuracy
of division with "-ffinite-math-only" for finite arguments and result.
Thanks,
-- Victor
More information about the Gcc-patches
mailing list