Friday, January 13, 2012

C++ Adding/Subtracting Large Numbers?

you should be more clear. you've tried float and long. these hold fundamentally different types of numbers. are we guaranteed to have integer input, or not? the range of signed 64-bit integers is -2^63 to 2^63-1 inclusive. 2^63-1 has 19 digits. c++ is machine-specific, so you should test out the range for example using bit shifts. note that there is not just long, but also long long. you might want to use a typedef to make this more manageable. you may very well need to look into bignum libraries / roll your own, unless you are fine with the rounding that occurs using (long) doubles to store large integers. good luck.

No comments:

Post a Comment