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?
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,n2, sum ;
cin >> n1 >> n2;
for(int i = 0;i<20;i++)
s = (n1[i]-48) + (n2[i]-48);
sum = '\0';
//not tested it but it should work.