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

# Re: [PATCH] Optimize x*x*x*x*x*x using 3 multiplications.

*From*: dewar at gnat dot com (Robert Dewar)
*To*: dewar at gnat dot com, pcarlini at unitus dot it
*Cc*: gcc at gcc dot gnu dot org
*Date*: Fri, 1 Aug 2003 05:52:06 -0400 (EDT)
*Subject*: Re: [PATCH] Optimize x*x*x*x*x*x using 3 multiplications.

> Indeed, very interesting! If you have got two more spare minutes, I
> would be curious to know a sketch of the explanation of this.
Consider the simpler case
a = x*x*x*x;
a = (x**2)**2;
the second form has only two multiplications instead of three.
So casual intuition (your deadly enemy when it comes to floating-point)
expects less loss of accuracy with only two operations.
But a careful error analysis shows that the error bounds for the second
case can be larger than those for the first case (obviously this depends
on the value of x in general).
An intuitive understanding (which is only slightly misleading :-) is that
in the first case, for each of the three multiplications, at least one of
the operands is error-free, but in the second case, the second multiplication
is between two quantities, both of which have rounding "errors".