delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/27/07:37:17

Date: Sun, 27 Dec 1998 14:37:30 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Nate Eldredge <nate AT cartsys DOT com>, Mad Cow <sw AT tenforward DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: StarMaps
In-Reply-To: <36856D22.9F3965BF@cartsys.com>
Message-ID: <Pine.SUN.3.91.981227143329.434J-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

On Sat, 26 Dec 1998, Nate Eldredge wrote:

> double distance(double x1, double y1, double x2, double y2)
> {
>   return sqrt(SQ(x1-x2) + SQ(y1-y2));
> }

Note that there's a library function called `hypot' that would do this 
for you, and avoid some common cases of over- and under-flow while at 
that.

Also, a word of advice: unless you *absolutely* __have to__, do NOT 
compute the square root; use the squared distance instead.  sqrt is slow 
in most cases, and should be avoided unless you can't.

For example, if you need the distance to compare two distances, compare 
the squared distances instead.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019