Results 1 to 6 of 6

Thread: Working with very large numbers.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2002
    Posts
    19

    Working with very large numbers.

    Hi,

    I am working on some code that is using some very large numbers. What is the absolute largest numeric data type that I can use before I have to use something fancy?

    What I am doing is making what is called a Rabbiski sequence, which is where the user types in 2 numbers, and I need to generate a sequence of 10 numbers, where is one is the product of the previous 2. As you can imagine, you get very large numbers very quickly. Once you have the 10 numbers, you need to print the sum of them.

    This is for an assignment, so please don't post any code, I don't want to get caught for plagarism. However, if you could let me know how to deal with large numbers in C++, or have any tips I would appreciate it.

    BTW - One problem that I am having is that I can generate the 10 numbers, however when I add them up and try to display the sum is just says "-NaN".

    Thanks in advance,

    Michael Bray

  2. #2
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    I do not know how to solve your problem. But I can tell you NaN stands for 'Not a Number' .

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2002
    Posts
    19
    Thanks,

    I don't know why it would say its not a number, but thanks for the tip. Put me in the right direction atleast

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    For integers there is long (= int on 32-bit systems) which can hold the numbers from -2^31 to 2^31-1, which should suffice. You can also use unsigned long which ranges from 0 to 2^32.
    The next larger number would be long long (or _int64 on VC++), which ranges from -2^63 to 2^63-1 (0 to 2^64 if unsigned).
    For floating point numbers there is the smaller float or the larger double, both have extreme ranges but loose much precision when storing large numbers.
    Only floating point numbers can hold the value NaN, which is usually the result of illegal operations like division by zero or square root of a negative number.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Fanatic Member sbasak's Avatar
    Join Date
    Aug 2001
    Location
    Globe Trotter
    Posts
    524
    You can represent large number using polynomial's link list

    for example.
    1023 = 1 * 10^3 + 0 * 10^2 + 2 * 10^1 + 3 * 10^0

    Using a link list, you can store only 1,0,2,3 instead of 1023. You can deal very high number is this way. While multiplying two numbers, use a ^ m * a ^ n = a ^ (m+n) concept.

    Hope it helps.
    Life is a one way journey, not a destination. Travel it with a smile and never regret anything.
    Yesterday is history, tomorrow is a mystery, today is gift - that's why we call it present.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Rather use the base 2^32 for maximum efficiency.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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