Reputation: 1293
So I am working on a game in which I would like to store very large numbers, in the trillions and quadrillions (a progression type game, a la Clicker Heroes, just doing it for fun).
Anyway, c# appears to have a 32-bit limit on integers, however, I can get floats to be very very large (eg. 999999999999999.0f)
However, is this the fastest way to store very large numbers in C#?
I do not need accuracy, so floating point-type solutions are fine. I just need speed and the ability to store very large integers.
Is a BigInt library the way to go? How do you recommend going about this?
Upvotes: 0
Views: 1013
Reputation: 155726
Anyway, c# appears to have a 32-bit limit on integers, however, I can get floats to be very very large (eg. 999999999999999.0f)
This is categorically false. C# has the long
and ulong
types which correspond to .NET's Int64
and UInt64
types, which are both 64-bit integers which represent the number-ranges:
Int64 : -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
UInt64: 0 to 18,446,744,073,709,551,615.
That's:
Eighteen quintillion, four hundred and forty six quadrillion, seven hundred and forty four trillion, seventy-three billion, seven hundred and nine million, five hundred and fifty-one thousand, and six hundred and fifteen.
And if you need to store even bigger numbers you can always implement your own UInt128
by joining two UInt64
values together and using schoolbook techniques to combine the two for common arithmetic operations.
Upvotes: 4