Why the C-Compiler SHOULD Do That.
utzoo!decvax!harpo!duke!unc!mcnc!idis!george
utzoo!decvax!harpo!duke!unc!mcnc!idis!george
Fri Jan 14 14:28:21 AEST 1983
References: seismo.194 uvacs.377 cca.4250
There seems to be a perpetuation of errors on this subject.
I hope to clarify the issues here.
1. Floating point arithmetic is not associative.
2. I assume that floating point arithmetic (on many machines)
is commutative.
3. The grouping of floating point arithmetic operators
is defined for the C language.
This may be determined by parentheses, precedence,
and grouping within a precedence level.
An expression may be replaced by another which
is mathematically equivalent with respect to
associativity or commutativity.
Unfortunately the "C Reference Manual" seems to formally
use one operator for both fixed point and floating
point interpretations.
Technically multiplication and addition are not
associative in the C language because they are not
associative in their floating point contexts.
Section 7. of "C Reference Manual" says:
"Expressions involving a commutative and
associative operator (*, +, |, ^) may be
rearranged arbitrarily, even in the prescence
of parentheses; to force a particular order
of evaluation an explicit temporary must
be used."
The listing of "*" and "+" there must have been an error.
Some compilers seem to take the reasonable liberty
of treating multiplication and addition as associative
operators when restricted to fixed point contexts.
4. Order of evaluation may be undefined.
Presumably sub-expressions should be evaluated
in such a way that does not violate the meaning
of the expression grouping, which is not subject
to dynamic interpretation.
George Rosenberg
duke!mcnc!idis!george
decvax!idis!george
More information about the Comp.lang.c
mailing list