# Need help with making number system for idle game

So, I want to create a new game. I have problems with how to store large numbers in the game and how to output them. I have written a small pseudo code that contains everything I need to play the game (Did I forget anything?).

# represent  our number
struct BigNumber {
double base; # (or mantissa)
double exponent;
}

# create new number
function NewBigNumber(double b, double exp) {
return BigNumber{
base = b;
exponent = exp;
}
}

# now if we have to BigNumbers we want add operation (+)
# and other operations (-), (*), (/)
# +
# if numbers have same exponent part
if (n.exponent = m.exponent) {
double new_base = n.base + m.base;

#create new BigNumber with new base
return NewBigNumber(new_base, n.exponent);

} else {
#?????????
}
}

# -
function subtraction(BigNumber n, BigNumber m){

}

# *
function multiplication(BigNumber n, BigNumber m){

}

# /
function division(BigNumber n, BigNumber m){

}


As you can see, I will use Scientific notation

I have a problem with the addition operation (and other), what if the exponent part of numbers are different?

Next I have this code.

# If we have achievement systems
# we need function equals of two numbers
function equals(BigNumber n, BigNumber m){
if (n.base = m.base && n.exponent = m.exponent){
return True;
} else {
return false;
}
}


And finally, I need the function to output numbers nicely.

suffices = [
'K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'Oc', 'No', 'Dc', 'Ud',
'Dd', 'Td', 'Qad', 'Qid', 'Sxd', 'Spd', 'Od', 'Nd', 'V', 'Uv', 'Dv',
'Tv', 'Qav', 'Qiv', 'Sxv', 'Spv', 'Ov', 'Nv', 'Tt'
];
# now we need "good view numbers" function
# for exapmle
# 1000 - 1000
# 1000000 - 1Million
function(BigNumber n) {
#????????
}

• Have you considered to just use an existing big number library? – Philipp Feb 5 at 11:35
• I have seen plenty of these game that just use doubles. And yes, the precision is lost, and you get beyond safe integers. By that time it is usually not a problem because the increments are very high too. If you do not want that, I'd side with Philipp, just use a third party big number library. What language is this? I do not know if there an open source, ready for production, big number library for your language ... but there are for others, worst case scenario you port one. – Theraot Feb 5 at 13:57
• These libraries contain a lot of unnecessary things that I don't need (for example, a sine function for a large number). The code in them is very large, I would like someone to explain to me on my fingers what functions are missing in my code and how to add these numbers. – 12345654321 Feb 5 at 16:16
• @12345654321 How are we supposed to know what functions your game needs when we don't know anything about your game? For example, how should we know that your game does not need a sine function for big numbers? – Philipp Feb 7 at 14:27
• I write prototype my game. But now it use just simple double/ I want to replace double to scientific notation – 12345654321 Feb 7 at 16:37

• It works with all the basic math operators +, -, *, /, % and ** (division will round to 0).
• It also works with the comparison operators like ==, >, <= etc.
• It can be expressed as a literal by using the suffix n. (const ONE_NONILLION = 1000000000000000000000000000000n).