This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC beaten by ICC in stupid trig test!



On Mar 24, 2004, at 11:12 AM, Joe Buck wrote:


On Wed, Mar 24, 2004 at 02:10:13PM -0500, Paul Koning wrote:
 Joe> Consider a, b, and c as single precision floating point values,
 Joe> and a=1, b=-1, c=1.2345e-8.  (a+b)+c will compute as 1.2345e-8.
 Joe> a+(b+c) will return zero, as will (a+c)+b.

I don't have a C standard, but my copy of Harbison & Steele says what
I expected about parentheses: "Parentheses do not necessarily force a
particular evaluation order".

This was true of K&R C, but I seem to recall that the standards committee
changed that. Any standards gurus out there care to comment?

This is correct. My copy of H&S (1987) is explicit that reassociation is allowed
even when that would change the result. It does have an appendix on
Draft Proposed ANSI C, as it was then, but that also does not mention the rule
that became standard; apparently this was introduced late in the standardization
process. (It does list unary + as a means of forcing order of evaulation, thus:
(+(a+b))+c
Unary minus did not have this effect. I don't much like the rule that's in the standard,
but I have to admit it's better than that.)


The current standards define order of evaluation implicitly from the parsing order.
Rearrangements are permitted only if they can't change the result (generally true
for integer, not for FP). Thus, it is more restrictive than Fortran, where K&R C was
less so.


But weren't we talking about -ffast-math? Standards are irrelevant to that discussion.
-ffast-math is for things that aren't safe according to the standard, but are frequently
useful; that's what it's for.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]