math function speed

ggs at ulysses.UUCP ggs at ulysses.UUCP
Tue Feb 17 13:23:18 AEST 1987


> mouse at mcgill-vision.UUCP (der Mouse):
> >I would really like a C compiler that produces anything that could
> >*touch* the "Kahan's magic square root" code of the 4.3 VAX libm.

Actually, I would too.  But most of the advantages of assembly language
come in the first few lines, where a few deft type puns compute a first
approximation of the sqrt by dividing the exponent by two.  The rest
would be straight C but for the mixing of single-precision with
double-precision.

In article <5622 at brl-smoke.ARPA>, gwyn at brl-smoke.ARPA (Doug Gwyn ) writes:
> The UNIX System V Release 2.0 sqrt routine, written in C, runs about
> half as fast as the 4.3BSD assembly code, and is about twice as accurate.

But the deft type pun in assembly language is still there; it has been
moved to frexp.s.

What's your definition of twice as accurate?  In 100,000 tests of random
arguments distributed over the positive range, I counted 8634 cases
with a 1-bit error and none worse.  Compared with most other math
functions, this is quite good.  For my reference I used a slow
algorithm that computes the "exact" answer to 1 extra bit and then
rounds.
-- 
Griff Smith	AT&T (Bell Laboratories), Murray Hill
Phone:		1-201-582-7736
UUCP:		{allegra|ihnp4}!ulysses!ggs
Internet:	ggs at ulysses.uucp



More information about the Comp.lang.c mailing list