This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: /internet
- To: Joe Buck <jbuck at Synopsys dot COM>
- Subject: Re: /internet
- From: Stephen L Moshier <moshier at mediaone dot net>
- Date: Wed, 16 Dec 1998 14:45:23 -0500 (EST)
- cc: Tim Hollebeek <tim at wagner dot Princeton dot EDU>, law at cygnus dot com, tprince at cat dot e-mail dot com, bosch at gnat dot com, burley at gnu dot org, egcs at cygnus dot com, hjstein at bfr dot co dot il
- Reply-To: moshier at mediaone dot net
> Does IEEE require left-to-right evaluation of y = a * b * c * d;
> when there are no parentheses present?
I think that IEEE does not actually say anything about it. C9X, however,
does contain some remarks such as the following, which might have come
from NCEG.
[#14] EXAMPLE 5 Rearrangement for floating-point expressions
is often restricted because of limitations in precision as
well as range. The implementation cannot generally apply
the mathematical associative rules for addition or
multiplication, nor the distributive rule, because of
roundoff error, even in the absence of overflow and
underflow. Likewise, implementations cannot generally
replace decimal constants in order to rearrange expressions.
In the following fragment, rearrangements suggested by
mathematical rules for real numbers are often not valid (see
F.8).
double x, y, z;
/* ... */
x = (x * y) * z; // not equivalent to x *= y * z;
z = (x - y) + y ; // not equivalent to z = x;
z = x + x * y; // not equivalent to z = x * (1.0 + y);
y = x / 5.0; // not equivalent to y = x * 0.2;
5.1.2.3 Environment 5.1.2.3
16 Committee Draft -- August 3, 1998 WG14/N843
[#15] EXAMPLE 6 To illustrate the grouping behavior of
expressions, in the following fragment
int a, b;
/* ... */
a = a + 32760 + b + 5;
the expression statement behaves exactly the same as
a = (((a + 32760) + b) + 5);
due to the associativity and precedence of these operators.
Thus, the result of the sum (a + 32760) is next added to b,
and that result is then added to 5 which results in the
value assigned to a. On a machine in which overflows
produce an explicit trap and in which the range of values
representable by an int is [-32768, +32767], the
implementation cannot rewrite this expression as
a = ((a + b) + 32765);
since if the values for a and b were, respectively, -32754
and -15, the sum a + b would produce a trap while the
original expression would not; nor can the expression be
rewritten either as
a = ((a + 32765) + b);
or
a = (a + (b + 32765));
since the values for a and b might have been, respectively,
4 and -8 or -17 and 12. However, on a machine in which
overflow silently generates some value and where positive
and negative overflows cancel, the above expression
statement can be rewritten by the implementation in any of
the above ways because the same result will occur.