Mail Archives: djgpp/1998/12/27/07:37:17
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 -