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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Jorville
Wanderer


Joined: 30 Apr 2006
Posts: 58
Location: Brookhaven, MS

PostPosted: Wed Oct 07, 2009 6:07 am   

decimals and math
 
ok, im sure ive missed something somewhere, ive tried every combination of %float and %int i can think of and i must not be putting it in the right place, im trying to get it to display the number preferabl;y rounded but i also want to know how to show the decimal form too, here is what i got:

Code:

#MATH testvar2 (@testvar/100)
#PRINT @testvar2


testvar is 65, so 65/100 should be 0.65, instead it gives me 0

thanks for the help, i know its something simple
_________________
Jorville
Player on SWMUD
Reply with quote
Fidel
Beginner


Joined: 07 Oct 2009
Posts: 19
Location: Poland

PostPosted: Wed Oct 07, 2009 9:12 am   
 
Hi,

@testvar is integer so before / You have to cast it with %float()

Code:

#MATH testvar2 (%float(@testvar)/100)
#PRINT @testvar2

Pawel
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Oct 07, 2009 4:50 pm   
 
If you just use integers, then CMUD defaults to integer math. To use floating point math, you can use %float as Fidel mentioned, or you can just make one of your numbers a floating point value, like this:
Code:
testvar2 = (@testvar/100.0)
#PRINT @testvar2
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Thu Oct 08, 2009 5:25 am   
 
Is there a good reason for the math to be carried out like this? I'd imagine scripts would be faster if there weren't tons of %float() commands to make the math work normally. A simple function to imitate integer math would make much more sense and alleviate this question being asked 50 times.
Reply with quote
Zugg
MASTER


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

PostPosted: Thu Oct 08, 2009 4:22 pm   
 
Chris, I'm not sure what you are asking. Integer math is much much faster than floating point and most MUD scripts do not need floating point, so that is why CMUD defaults to Integer math. Adding the ".0" decimal to force floating point is easy and does not slow down any parsing. And even the %float function is very fast as it's handled internally by the compiler (just changes the data type of the current expression on the stack).

So there isn't any performance issue here. And the current default of Integer Math has been the same as in zMUD for the last 12 years and hasn't caused any support issues.

The mistake would be for CMUD to default to Floating point which would then slow down all scripts for no good reason.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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