anther baby step - namespace adjustments

Roger Sayle roger@eyesopen.com
Tue Jul 22 22:29:00 GMT 2003


Hi Kai,

Kai Henningsen wrote:
> Roger Sayle wrote:
> > This function is an extremely poor approximation to sqrt found
> > by a very slow algorithm.
>
> Are you sure about that? This looks like Newton's method, which is
> anything but slow and produces approximations as close as you like.

Whilst it is true that Newton's method for finding square roots can be
made efficient and accurate, the current implementation in approx_sqrt
is by design neither as efficient nor as accurate as it could be.

High performance sqrt implementations normally recast their equations
to calculate the reciprocal of the square root, this avoids an
expensive division during each iteration.  Many also attempt to
find a good initial approximation to converge from, the approx_sqrt
starts from the value x (even using the value x/2 would save an
iteration).

But the real approximation is the "d <= 0.0001" convergence criterion.
Again this is appropriate for its current use, but not particularly
helpful if you wish to calculate sqrt(0.0001), for example, and there
are probably very large values of x for which this implementation may
fail to converge.


For this particular application, there are also some very clever
integer square root algorithms that might even be appropriate.
See, for example, http://www.azillionmonkeys.com/qed/sqroot.html


I was just surprised that Zack's patch was being stalled in the
review process by discussions about linking -lm, which although
technically interesting, wasn't relevant in this instance.

Roger
--



More information about the Gcc-patches mailing list