Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
BlackSmith
Apprentice


Joined: 08 Dec 2002
Posts: 152

PostPosted: 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.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: 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.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net