Article View: comp.arch
Article #10962Re: integer distance or sqrt
From: Eliot Moss
Date: Mon, 16 Nov 1992 14:47
Date: Mon, 16 Nov 1992 14:47
19 lines
1820 bytes
1820 bytes
I don't recall the details, but there are more clever ways to calculate distance (sqrt(x^2 + y^2)), which avoid the overflow problems of the squaring and summing. I suspect the principle is something like this (assuming x > y >= 0): dist = x * sqrt (1 + (y/x)^2). One then applies an appropriate approximation method to this instance of sqrt (note that 0 <= y/x < 1). Of course, if you're sure you won't overflow, and an integer result is accurate enough for you, I'd suggest the direct method, unrolling the Newton's Method iteration an appropriate fixed number of times by hand. (The algorithm converges very rapidly, about doubling the number of bits on each iteration; it is about the only approximation method with such rapid convergence.) -- J. Eliot B. Moss, Associate Professor Visiting Associate Professor Department of Computer Science School of Computer Science Lederle Graduate Research Center Carnegie Mellon University University of Massachusetts 5000 Forbes Avenue Amherst, MA 01003 Pittsburgh, PA 15213-3891 (413) 545-4206, 545-1249 (fax) (412) 268-6767, 681-5739 (fax) Moss@cs.umass.edu Moss@cs.cmu.edu
Technical Details
Message-ID:
<MOSS.92Nov16094710@CRAFTY.cs.cmu.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!ogicse!das-news.harvard.edu!cantaloupe.srv.cs.cmu.edu!netnews-2.srv.cs.cmu.edu!mossReferences:
<55F0TB1w165w@tsoft.sf-bay.org> <CLIFFC.92Nov15184340@miranda.rice.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!das-news.harvard.edu!cantaloupe.srv.cs.cmu.edu!netnews-2.srv.cs.cmu.edu!moss From: moss@cs.cmu.edu (Eliot Moss) Newsgroups: comp.arch Subject: Re: integer distance or sqrt Message-ID: <MOSS.92Nov16094710@CRAFTY.cs.cmu.edu> Date: 16 Nov 92 14:47:10 GMT Article-I.D.: CRAFTY.MOSS.92Nov16094710 References: <55F0TB1w165w@tsoft.sf-bay.org> <CLIFFC.92Nov15184340@miranda.rice.edu> Sender: news@cs.cmu.edu (Usenet News System) Reply-To: moss@cs.cmu.edu Organization: Dept of Comp and Info Sci, Univ of Mass (Amherst) Lines: 19 In-Reply-To: cliffc@rice.edu's message of 16 Nov 92 00:43:40 GMT Nntp-Posting-Host: crafty.fox.cs.cmu.edu