|
-
Dec 1st, 2007, 12:22 AM
#1
Thread Starter
Member
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?
-
Dec 1st, 2007, 10:07 AM
#2
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.
-
Dec 1st, 2007, 09:45 PM
#3
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
Visual Studio 6, Visual Studio.NET 2005, MASM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|