I'm writing a Statistical Calculator for a videogame. Some of the statistics use numbers that are longer than 16 digits, and from what I can tell, a longdouble can only hold up to 15 digits (or double).
Should I use a variable to store this data, or would using an algorithm to split it into smaller numbers and re-construct it from those numbers be more suitable?
I'd just grab a library to handle this, unless you wanna handle it yourself.
This one is pretty lighweight and will definitely cover any number you could want. http://www.ttmath.org/faq
Floating point numbers are designed to be able to handle very small values and very large values. They can contain much more than 15 digits but only the 15 right-most digits will be without rounding errors, loosely speaking. You will get rounding errors but for many applications they are good enough.
The precision of the different floating point numbers really depends on your compiler. You can run this program to find out.
You could use a char array to store nos. See the foll code as an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//code for adding 2 20 digit nos.
char n1[20],n2[20], sum [22];
int s;
cin >> n1 >> n2;
sum[0]=0;
for(int i = 0;i<20;i++)
{
s = (n1[i]-48) + (n2[i]-48);
sum[i+1]=s%10;
sum[i]+=(s/10)*10+48;
}
sum[22] = '\0';
cout<<sum;
//not tested it but it should work.
There are similar libraries available on the web like a good one is ttmath(http://www.ttmath.org/)