Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!lll-lcc!ames!ucbcad!ucbvax!ulysses!ggs From: ggs@ulysses.UUCP Newsgroups: comp.lang.c Subject: Re: math function speed Message-ID: <2050@ulysses.homer.nj.att.com> Date: Mon, 16-Feb-87 22:23:18 EST Article-I.D.: ulysses.2050 Posted: Mon Feb 16 22:23:18 1987 Date-Received: Tue, 17-Feb-87 19:27:06 EST References: <4943@mimsy.UUCP> <2550005@hpisod2.HP> <756@unc.unc.UUCP> <5622@brl-smoke.ARPA> Distribution: na Organization: AT&T Bell Laboratories, Murray Hill Lines: 28 Summary: please define "twice" > mouse@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@brl-smoke.ARPA>, gwyn@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@ulysses.uucp