@Kiwasi
Thanks for the link. But I did not mean an example of a idle game. But an example of an idle where you have some score that grows exponentially, which would justify the need to encode numbers of the order of 1e900.
Do you really technically need to handle (doing arithmetic and such) numbers of that order?
Many games, including Cookie Clicker has max values at (1.79e308), after reaching that number, the ânumbersâ become infinity. I donât want that kind limitation on my game, so I want something that can handle it.
I donât think you technically need to store such big numbers, you could do simple tricks instead. You could simply keep track of 10-exponent (or unit prefix) into a separate integer, like:
0:unit (1e0)
1:deca (1e1)
2:hecto (1e2)
3:kilo (1e3)
âŚ
Then as you number increase, you just have to increment your unit prefix and divide your number by 10 for each increment. Using this trick with a uint, you number can go over 1e4294967295. Would that be enough?
Yes, count magnitudes and work around it like that. Idle games of this sort typically donât drop down before the reset, so losing a few fractions wonât hurt. One septaquintillion here, one septaquintillion there - it all adds up to REAL money eventually anyway.
You can increment magnitude in thousands (kilo, million etc.), and divide it by three to get the symbol from a table. But you should probably look at a way to incrementally build up new symbols as you get into the REALLY silly numbers, so that a lookup-table isnât necessary. Or make a hybrid solution where you generate this table at the start. Also leave an alternative display option with exponents. You CAN go to infinity and beyond with a few sneaky tricks
Since OP agreed already when they saw my demo code that does exactly that.
/// <summary>
/// Represents a value as sig * 10^exp
/// Or basically, sig following by _exp zeros
/// </summary>
public struct LargeInt
{
private long _sig;
private int _exp;
public LargeInt(int value)
{
_sig = value;
_exp = 0;
}
public LargeInt(long value)
{
_sig = value;
_exp = 0;
}
public override string ToString()
{
if (_exp == 0)
return _sig.ToString();
else if (_exp > 0)
return _sig.ToString() + new string('0', _exp);
else
return string.Empty; //do we want to support fractions???
}
public static implicit operator LargeInt(int value)
{
return new LargeInt(value);
}
public static implicit operator LargeInt(long value)
{
return new LargeInt(value);
}
public static LargeInt operator +(LargeInt a, LargeInt b)
{
if(a._exp < b._exp)
{
var c = b;
b = a;
a = c;
}
int dif = a._exp - b._exp;
if (dif > 19) return a; //out of range
long s = b._sig;
while (dif > 0)
{
dif--;
s /= 10;
}
a._sig += s;
return a;
}
//implement other operators
}