|
BlackSmith Apprentice
Joined: 08 Dec 2002 Posts: 152
|
Posted: Mon Oct 09, 2006 1:15 am
Why zMud calculates wrong? |
pen and paper
15 / 200 = 0.075
zMud 7.21
#Say %eval(%float(15)/200)
0,0750000029802322 |
|
_________________ BatMUD Best MMORPG around since 1990 telnet://bat.org:23
~ Magic & Mind beats Chrome & Meat anytime ~
Pattern(s) in PERL. Using Cmud 1.34/2.09 & BatClient. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Oct 09, 2006 4:42 pm |
That's because zMUD only uses single-precision floating point. This kind of issue is a standard result of representing floating point numbers in a binary format. Even with double-precision you will see differences after several decimal places. Computer floating point math is only valid for a certain number of decimal places. Unlike integers, floating point values cannot be represented "perfectly" in binary.
zMUD has a %norm function that will truncate floating point values to the proper number of digits so that you won't see this problem. But this kind of issue is present in all computer programs...some just do a better job of hiding it, or some use other storage formats (like BCD) rather than the single or double-precision IEEE floating point formats. |
|
|
|
|
|