-
big numbers
i am writing a C++ program to compute if a number is prime or not. i basically have a for loop set up. it tests all the numbers from 2 to the number specified by the user. it can take a little while but thats ok (i'm not worried about speed) however i can get an overflow error. i type in a large number and it will say its prime but it is not testing the right number becase it is to large to be stored.
i am a computer engineering student, i am in a class that is well kinda slow for me. my professor encouraged me to try some on my own and gave me this idea.
my question is how can i store really big numbers, like about a trillion? or even more?
-
Re: big numbers
A trilion will fit in a 64 bit integer. Depending on the compiler the data type for this is 'long long' or '_int64'.
If you want even bigger numbers things become harder. C++ does not support arbitrary precision numbers by itself, you need a library for that. For instance GMP.
-
Re: big numbers
Or, you can combine two 32-bit integers into one, using something similar to the LARGE_INTEGER union that 32-bit Windows uses..
chem