Thread: longer numbers?
View Single Post
Old 08-21-2003, 06:38 PM   #7
welcor
Member
 
Join Date: Apr 2002
Location: Aarhus, Denmark, Europe
Posts: 59
welcor is on a distinguished road
Send a message via ICQ to welcor
For very large numbers you can 'roll your own system'.

Pseudocode;
[code]
internally have 2 (or more vars)
int exp1
int exp2
int exp1_max = 100000;

When adding;
exp1+= add
while (exp1 >= exp1_max) {
 exp2++
 exp1 = exp1 - exp1_max
}
When displaying;
"You have %d%05d exp.", exp2, exp1
[/quote]

This will, by using two ints, allow for numbers approaching 214748364700000 (which is 214 trillion for you americans out there, and 214 billions to the rest of us. )

As a side note - even though I see that following the theme of dragonball is a main focus - I think a design that needs numbers in that range is absurd. There is nothing preventing you from just doing this:
[code]
"You have %d000 exp.", exp
[/quote]
When dealing with numbers up to 2.1 billion, you don't really care about those small changes below 1k, do you ? This little change should give you enough for the first 2k billions. (2 trillions) and doesn't give you any extra trouble.

In short - if you need such high numbers, your design is flawed.
welcor is offline   Reply With Quote