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 (-), (*), (/)
# +
function adding(BigNumber n, BigNumber m){
# if numbers have same exponent part
if (n.exponent = m.exponent) {
# adding base here
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) {
#????????
}