Results 1 to 3 of 3

Thread: big numbers

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    46

    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?

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771

    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.

  3. #3
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    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
  •  



Click Here to Expand Forum to Full Width