This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: How to determine that 2.0 == (float) 2 in a front-end.
- From: Erik Schnetter <schnetter at uni-tuebingen dot de>
- To: gcc at gcc dot gnu dot org
- Date: Sun, 30 Jun 2002 15:04:31 +0200
- Subject: Re: How to determine that 2.0 == (float) 2 in a front-end.
- Organization: Theoretische Astrophysik Tuebingen
Robert Dewar wrote:
>
> x**6.0 can be rendered as x**6 (which is y=x*x, z=y*y, z=z*y).
>
> Note that this is liikely less accurate than calling a well written
> pow routine.
>
> Note that for example x*x*x*x is generally more accurate than x**2**2
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.
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.
-erik
--
Erik Schnetter <schnetter@uni-tuebingen.de>
Web: http://www.tat.physik.uni-tuebingen.de/~schnette/