Thread: Large Numbers

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    58

    Large Numbers

    Alright, here's my problem. I need to store a number thats as big or higher than 1661713756910382300 into a data type other than a string or array. The problem with a string/array is that when i use one of the string -> number functions (atoi, atol, strtod...) It either completly messes it up, int makes it negitive, or formats it in such a way that i can't use it. Example code of what i need to do.

    Code:
    double number=1661713756910382300;
    
    if(number % 100 = 0)
    {
         insert stuff here;
    }
    I'm running MSVS any ideas guys?

  2. #2
    I know there is an __int64 that you can use and maybe there's an __int128 that you can use - that would take care of your number.

    __int64 and beyond are MS specific.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    If a number is too big, you'll have to split your number into two or more pieces. Imagine that you have counters that go up to one million and you need to count to 1.5 million... One counter counts the "number of millions" and is set to one... Another counter is set to 500,000.

    This is where the concept "double" comes from, although it's handled by the compiler. Without using a scheme like this, an 8 bit processor could only handle numbers up to 256 and a 16 bit processor could only handle numbers up to 64k.

    I'm not at my compiler, so no examples that I haven't tried-out! I'm asssume there are libraries to help with this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to deal wth large numbers
    By bvgsrs in forum C++ Programming
    Replies: 2
    Last Post: 06-18-2007, 06:16 AM
  2. Handling Large Numbers
    By Xzyx987X in forum C Programming
    Replies: 2
    Last Post: 05-03-2004, 02:33 PM
  3. Using really big numbers!
    By Machewy in forum C++ Programming
    Replies: 11
    Last Post: 02-26-2004, 10:49 AM
  4. Help needed with VERY large numbers.
    By jwarner in forum C++ Programming
    Replies: 4
    Last Post: 01-18-2004, 12:01 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM