View Single Post
Old 07-05-2012, 03:35 PM   #48
dentin
Member
 
Join Date: Apr 2008
Home MUD: Alter Aeon
Posts: 245
dentin is on a distinguished road
Re: Can MUDs implement range/distance?

Camlorn,

By casting the xdiff and ydiff to floating point, he gives them arbitrary range. If they start out as ints, the difference ends up floating point. If you square an int, it can overflow. If you square a double precision floating point number, it probably wont (and if you start from an int, its guaranteed not to.)

Adding the two squares, each of which is now guaranteed not to overflow, also doesn't produce an overflow. So the square root function always has a valid input.

-dentin

Alter Aeon MUD
dentin is offline   Reply With Quote