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 incombine)
- To: Linus Torvalds <torvalds at transmeta dot com>
- Subject: Re: What is acceptable for -ffast-math? (Was: associative law incombine)
- From: Stephen L Moshier <moshier at mediaone dot net>
- Date: Sun, 29 Jul 2001 17:03:16 -0400 (EDT)
- cc: moshier at moshier dot ne dot mediaone dot net, tprince at computer dot org, gcc at gcc dot gnu dot org
- Reply-To: moshier at moshier dot ne dot mediaone dot net
> > Floating point arithmetic, IEEE or otherwise, does not obey the
> > associative or distributive laws.
>
> This is YOUR opinion.
That is not just an opinion, it is simple arithmetic.
Further, GCC is supposed to be standards compliant by default. You
seem to be advocating that GCC should, without warning, generate
programs that violate the standard and are mathematically wrong.
The C99 standard says the following, among other things, about floating
point transformations:
[#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;