TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Non-integer maths

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Mon Oct 10, 2011 9:48 am    Post subject: Non-integer maths Reply with quote

TinTin++ #MATH command is advertised as providing integer mathematics, but I was recently doing something (with a TICK regenerating procedure to work out when the MUD's internal clock changed hours) and I found that there is some limited non-integer maths availible (I guess using 'C' native variable promotion):
Code:
#MATH result 1/3; #SHOWME $result
0
#MATH result 1.0/3; #SHOWME $result
0.3
#MATH result 1.00/3; #SHOWME $result
0.33
#MATH result 1.000/3; #SHOWME $result
0.333
#MATH result 1.0000/3; #SHOWME $result
0.3333
#MATH result 1.00000/3; #SHOWME $result
0.33333
#MATH result 1.000000/3; #SHOWME $result
0.333333
#MATH result 1.0000000/3; #SHOWME $result
0.3333330

#VARIABLE x 1; #MATH result ($x + 0.000)/3; #SHOWME $result
0.333

Basically by added a zero with N places of decimal we also get a result to N decimal places, where N <= 6. Is this an undocumented software feature Cool or can we accept it as designed? I would like #MATH functions to provide INT, CEILING and FLOOR integer results given a (possibly) non-integer arguments (would 'i', 'c', and 'f' work alongside the existing 'd' for random dice roll for example) is this a 'feasable idea'?

NB I recognise it is possible to obtain an INT result by using a #REGEXP {%d.%d} on a variable and then just taking the &1 result.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Mon Oct 10, 2011 5:10 pm    Post subject: Reply with quote

#math supports double precision math, not sure why the precision is only 6 digits instead of 16, I guess it'll suffice for most people.

Probably best to write a floor and ceiling functions yourself given few people would use it.

#format supports %d for integers, and %m for tintin math strings.

I probably need to add %f to #format to handle floating point digits a little better as I don't think you can currently easily down-convert 2.234 to 2.23.
Back to top
View user's profile Send private message Send e-mail
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Tue Oct 11, 2011 11:55 am    Post subject: Reply with quote

Um, checking out the maths stuff and division by zero is not caught as an error! Crying

Code:
#MATH result 10/2; #SHOWME $result
5
#MATH result 10/1; #SHOWME $result
10
#MATH result 10/-1; #SHOWME $result
-10
#MATH result 10/0.5; #SHOWME $result
20.0
#MATH result 10/0; #SHOWME $result
10
Given that we could be using a variable for the divisor and sometimes that variable may not be instantiated correctly (and thus be read as zero?) I think we HAVE to detect and report to the user if a division by zero is attempted...
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Tue Oct 11, 2011 4:53 pm    Post subject: Reply with quote

I guess I can let tt++ crash on a division zero.
Back to top
View user's profile Send private message Send e-mail
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Tue Oct 11, 2011 7:02 pm    Post subject: Reply with quote

Seriously? Confused

Ah, looking through the source code there ARE error messages commented out...

Use the source, Luke Skywalker!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Feature Requests All times are GMT - 5 Hours
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
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group