Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

Re: Conflicts between C standard and 754-2008



Cc list because I am not on the 754 mailing list and don't know where this started.

On Jan 12 2011, Vincent Lefevre wrote:
On 2011-01-06 15:05:35 +0200, Hossam A. H. Fahmy wrote:

and without any parenthesis I assumed that the evaluation will always
proceed from left to right and I swapped the second and third term. So we
are getting:
(z-y)+x = 100
and
(z+x)-y=0

which is as expected in 754. However, C says that (-y)+x is the same as x+(-y) so an optimizing compiler can assume that the two statements z-y+x and z+x-y (just commutativity on the 2nd and 3rd term) are equivalent which they are not under 754.

No, you're also using the associativity here, because a+b+c is
interpreted unambiguously as (a+b)+c. And from (a+b)+c to (a+c)+b,
you're not using the commutativity only, but a succession of
commutativity and associativity transformations.

No, that is NOT true, and never has been!  Please stop propagating that
myth.  The word that is false (and I mean false) is "unambiguously", and
without that it is still misleading.  All that is unambiguous is the
PARSING - the evaluation has NEVER been clearly specified.

There was a thoroughly confused debate in the late 1980s on this one
in WG14, on an even stronger form, which is whether compilers are allowed
to reorder across parentheses.  This(inter alia) had proposals for the
unary plus operator to enforce parentheses and double parentheses.  Yes,
I do mean +(a+b)+c and ((a+b))+c versus simple (a+b)+c.  No consensus
was reached and the eventual result was that the precise evaluation
order was left undefined by omission.

The interpretation of the C standard was drifting towards the parsing
order being the evaluation order, for different reasons, but WG14 has
NEVER clarified this point.  However, C99 really threw the cat among
the pigeons by introducing FLT_EVAL_METHOD and the FP_CONTRACT pragma.
In particular, the defaults are implementation-defined, NOT constrained
by either Annex F or IEEE 754, and permit the use of associativity.

God alone knows what the C standard specifies, because I can witness
from reflector debates that WG14 doesn't.


Regards,
Nick Maclaren.