[PATCH] Optimize x*x*x*x*x*x using 3 multiplications.

Robert Dewar dewar@gnat.com
Fri Aug 1 10:31:00 GMT 2003


> 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".



More information about the Gcc mailing list