How to determine that 2.0 == (float) 2 in a front-end.
Robert Dewar
dewar@gnat.com
Fri Jul 12 11:23:00 GMT 2002
<<Why is that? Naively, I would think that x*x*x*x (evaluated left to right)
has 3 multiplications in a row, while (x**2)**2 has only two. So, from an
error propagation point of view, the latter should be more accurate.
>>
It is always hard to get an intuitive feel for these results (the above
result is fairly easy to prove). Here is an attempt. In the case of
x*x*x*x, you have 3 multiplications but in the 2nd and 3rd, one of the
operands at least is exact. In the case of (x**2)**2 the second multiplication
has two potentially inexact operands so the error is multiplied.
<<Wrt your first statement: I assume that a "well written pow routine" would
calculate that as or similar to exp(6.0 * log(x)). This surely involves many
more floating point operations. Is it really more accurate? [Checking
glibc... Moving on to to http://oss.software.ibm.com/mathlib/...] Okay, it
seems to be. I'm impressed.
>>
no no you definitely cannot calculate x**y using exp and log, even with
perfectly accurate (last bit rounded) exp and log, this is a terrible
way of doing things. For a detailed analysis of this case see chapter
5 of my book on Microprocessors (McGraw Hill 1990).
More information about the Gcc
mailing list