|
raivenloth Newbie
Joined: 23 Feb 2003 Posts: 9 Location: USA
|
Posted: Fri Oct 17, 2003 6:08 pm
Math Limitations |
I have found this in about every version of zmud to date and was scanning through a posting and the point was raised that the buglist was growing short so I thought I would bring this up.
I play on a mud where I tend to take a percentage of the level and display it, it adds the current xp to level with the xp gained to find the total then divides it. well when you have about 40,000,000 it gets to about 50% then goes negative percentage. so instead of dropping to 40% say, it goes -55%. This is an example not exact numbers, but the point being that when handling large numbers zmud seems to choke. Though this could somehow be me, but I don't think so.
This also happens when taking an average exp/kill and trying to determine average kills to level.
-Zac |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Fri Oct 17, 2003 6:36 pm |
zMUD 6.26 uses 32-bit integers. The 32nd (largest) bit is used to indicate a negative number, so the largest number that zMUD can normally handle (as a number) is 2^32 - 1, which is 2,147,483,647.
This is standard for computer programs.
40 million is fine, but when you multiply it by 100 the product is 4 billion, well over the limit. Since you've reached large numbers, it's time to revise your formulas.
Replace (100 * X)/Y with X/(Y/100). |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Fri Oct 17, 2003 11:22 pm |
I used to use a varying precision formula. Since zMud treats all variables as strings, you can use the %len function to check how many digits it contains. The limit for 32 bit numbers is only encountered when the string is converted to a number for math functions. Then when it is large enough divide by a power of 10 before your intial multiplication, and multiply that back in after your final division. If it grows extremely large use string functions like %leftback to chop off the last few digits. Using the 2 methods in conjuction with numbers that are not powers of 10 but close, produces similar results while hiding the imprecision.
|
|
|
|
raivenloth Newbie
Joined: 23 Feb 2003 Posts: 9 Location: USA
|
Posted: Mon Oct 20, 2003 11:57 pm |
I appreciate the help, worked like a charm.
Now if I could just get a reply on my license. Gotta love it when you reformat and forgetting to jot down the license :P
-Raivenloth. |
|
|
|
|
|
|
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
|
|