Thread: Very larger integer calulator

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    2

    Very larger integer calulator

    I have to write a C++ program to add,multiply, and divide very large integer numbers of unlimited size. The book suggest breaking the number up like this 9876543210987654 =
    987 765 432 109 876 54 ..... and handling it like that I am totally lost on how to do this please help !

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    119
    Search Google for big int class and you will get lots of pre-written classes that overload the operators. You can look at these to see where to start. Basically you can store a num of any length in a string and write functions to do the math on them, all wrapped inside a class with the usual overloaded ops.
    -d-
    If you speak or are learning Spanish, check out this Spanish and English Dictionary, it is a handy online resource.
    What happens is not as important as how you react to what happens. -Thaddeus Golas

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    most mathematical operations of a computer involve addition on some level - subtraction becomes the addition of numbers in two's complement, multiplication repetitive addition, and division repetitive subtraction. here's a small set of classes that add binary bits just like a computer:

    Code:
    namespace adder {
     struct result {
      result & set(bool _sum, bool _carry) {
       sum = _sum, carry = _carry;
       return *this;
       }
      void clear(void) {
       set(0, 0);
       }
      result(bool _sum = 0, bool _carry = 0) {
       set(_sum, _carry);
       }
      bool sum, carry;
     };
     struct halfadder : result {
      result & add(bool a, bool b) {
       sum = xor_gate(a, b);
       carry = and_gate(a, b);
       return *this;
       }
      halfadder(bool a = 0, bool b = 0) {
       add(a, b);
       }
     };
     struct fulladder : halfadder {
      result & add(bool a, bool b, bool carry_in) {
       halfadder first(a, b);
       halfadder::add(carry_in, first.sum);
       carry = or_gate(carry, first.carry);
       return *this;
       }
      fulladder(bool a = 0, bool b = 0, bool carry_in = 0) {
       add(a, b, carry_in);
       }
     };
    } // namespace adder
    good luck!
    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;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM