Using huge numbers

This is a discussion on Using huge numbers within the C++ Programming forums, part of the General Programming Boards category; I would like to make my program calculate this: Code: cout <<(long double)pow((long double)2,2005)<<endl; but the answer is too big, ...

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    Using huge numbers

    I would like to make my program calculate this:
    Code:
    cout <<(long double)pow((long double)2,2005)<<endl;
    but the answer is too big, but there must be a way to calculate this in my program...

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,408
    You could consider using the GNU MP library.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    tere
    i wrote a program to deal with huge numbers a while ago. it's not hard to do this. to write a pow() just write a multiplication function and use it in a loop, it would be slow, yes, but it will get the job done.
    :wq

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,408
    it's not hard to do this.
    I agree, but it can be tedious if you're working on something else and just need bignum support. Not only that, but it isnt easy to make it run (relatively) fast.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    Quote Originally Posted by laserlight
    I agree, but it can be tedious if you're working on something else and just need bignum support. Not only that, but it isnt easy to make it run (relatively) fast.
    yes, you are right, laserlight. if he's working on something else, then it really isn't necessary, but if it's just a hobby project why not...
    :wq

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Displays 0:
    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int slow=2;
        for(int road=1;road<2005;road++){
        slow=slow*2;
        }
        cout<<slow<<endl;
        system("PAUSE");
        return EXIT_SUCCESS;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Outputting numbers in arrays
    By rachael033 in forum C++ Programming
    Replies: 10
    Last Post: 05-29-2007, 02:56 AM
  2. Program that prints numbers in columns
    By rayrayj52 in forum C++ Programming
    Replies: 12
    Last Post: 09-20-2004, 02:43 PM
  3. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 10:15 AM
  4. Line Numbers in VI and/or Visual C++ :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 02-10-2002, 09:54 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 05:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21