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

I understand your need for level of detail, but I'll leave that for KaVir if he feels it necessary. I can answer the float/double question though.

Single precision FP, which is the 'float' type in C, only has about 24 bits of precision even though it's a 32 bit number. The remaining 8 bits are the exponent, which means that it can take on values such as 1.5e16, even though the largest possible number that can fit in 32 bits is about 4e9.

Double precision FP, which is the 'double' type in C, has about 53 bits of precision, out of 64 bits total. The exponent on the 'double' type can be a lot bigger, so numbers like 1.5e60 are possible.

Wikipedia has a big article on the theoretical construction and design of floating point numbers in general; it might be worth reading that as well.

Since KaVir is using doubles here, he's got enough bits that he's probably not going to lose precision in any of the operations. But even if he used floats, the loss of precision would be 'close enough' for pretty much all meaningful situations. Remember that you can still add 1e-16 to 1e16 and get a result, even if the floating point representation lacks the precision needed. It just won't be perfectly accurate.

-dentin

Alter Aeon MUD
dentin is offline   Reply With Quote