Thread: Doing operations with very large numbers?

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    55

    Doing operations with very large numbers?

    Is there any particular solution for handling operations with, let's say, 50 digit numbers or more, without the help of third-party libraries?

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by thefeedinghand View Post
    Is there any particular solution for handling operations with, let's say, 50 digit numbers or more, without the help of third-party libraries?
    The only other option, obviously, is to write your own library.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    55
    Any tips on doing that? I came up with a solution that may not work or may not be efficient, basically store the number in a char array and then convert each element of the array to a integer and pass them to a integer array and start doing the operations and work from there....

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Do you know how to do + - * / on paper?

    Code:
     12
    +34
    =46
    If you know that, then sure it's very easy.

    It might not be particularly quick, but it will work.

    If you want efficiency, without using an existing library, then expect lots of hard work and research.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    I didn't want to use any third-party library for such a thing myself either, so I wrote my own, well two of them actually.
    They store the data as binary, one dynamically allocated, the other not.
    I'm considering writing another one that stores it as a string, also.

    Do you really want to know how to make your own? If so, you make a start, and we'll point you at a few resources on how to do the bits you aren't sure of.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. storing really large numbers like 100!
    By rodrigorules in forum C++ Programming
    Replies: 9
    Last Post: 01-23-2010, 03:04 PM
  2. Binary division of large numbers
    By hooper in forum C Programming
    Replies: 5
    Last Post: 06-01-2007, 02:33 AM
  3. Handling Large Numbers
    By Xzyx987X in forum C Programming
    Replies: 2
    Last Post: 05-03-2004, 02:33 PM
  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