This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: What is acceptable for -ffast-math? (Was: associative law in combine)
- To: aoliva at redhat dot com, gdr at codesourcery dot com
- Subject: Re: What is acceptable for -ffast-math? (Was: associative law in combine)
- From: dewar at gnat dot com
- Date: Mon, 30 Jul 2001 23:53:53 -0400 (EDT)
- Cc: amylaar at redhat dot com, dewar at gnat dot com, gcc at gcc dot gnu dot org,moshier at moshier dot ne dot mediaone dot net, torvalds at transmeta dot com,tprince at computer dot org
<<The C/C++ Standard, for example, say that a/b/c is evaluated as
(a/b)/c. Someone proposed that it should be evaluated as a/(b*c)
-- which of course is incorrect -- when optimizing.
>>
Well now, let's be a little careful here ....
When the C standard says a/b/c is evaluated as (a/b)/c, it means that the
result is *as if* it were computed that way, and a compiler is of course
free to compute a/(b*c) if the result is still correct.
Now for the integer case we know exactly what "still correct" means, it
means that if we can prove that a/(b*c) does not overflow, and always
gives the same result as (a/b)/c, then of course the compiler can compute
it the first way.
What we are discussing is what "still correct" means for floating-point.
Most certainly the C and C++ standards do not give an exact prescription
for floating-point values. You actually have to say quite a bit to even
get near to the point where you can really answer the question accurately.
Let's look at the exact rules in Ada for example. Of course Ada requires
that a/b/c be computed as if it were (a/b)/c. But Ada also defines a
concept of model numbers and model intervals, and any evaluation scheme
that provides a guarantee that the result is in the appropriate model
interval is permissible. Let's give an example.
If you see a / 2.0 / 2.0
it is absolutely definition OK, to compute this particular expression
as a / 4.0 in any language no matter WHAT the standard says, since the
result is exactly the same. But for other divisors this is not necessarily
true.
So the "which of course is incorrect" is a bit too glib here.