Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

sint.h

Go to the documentation of this file.
00001 #ifndef BIGINT_H
00002 #define BIGINT_H
00003 
00004 #include <iostream.h>
00005 #include <string.h>
00006 
00007 // author: Owen Astrachan
00008 // modified by Claire Bono
00009 //
00010 // implements an arbitrary precision integer class
00011 //
00012 // supports non-negative numbers only
00013 //
00014 // constructors:
00015 //
00016 // sint()            -- default constructor, value of integer is 0
00017 // sint(int n)       -- initialize to value of n (C++ int)
00018 //       precondition: n >= 0
00019 //
00020 // sint(const string & s) -- initialize to value specified by s
00021 //        e.g.    sint big("121212121212123123123123123");
00022 //                (1 is most sig. digit of big; 3 is least sig. digit of big)
00023 //        precondition: s has only digit chars and is not empty
00024 //
00025 // sint(const sint & b)  -- copy constructor
00026 //
00027 //
00028 // *****  arithmetic operators:
00029 //   
00030 // void operator += (const sint & b)
00031 //          modifies object by adding a sint to it
00032 //
00033 // sint operator + (const sint & a, const sint & b)
00034 //          adds two sints together, returns result
00035 //
00036 // void operator *= (const sint & b)
00037 //          modifies object by multiplying by sint
00038 //
00039 // sint operator * (const sint & a, const sint & b)
00040 //          multiplies two sints together, returns result
00041 //
00042 //  ***** logical operators:
00043 //
00044 // int operator == (const sint & a, const sint & b)
00045 //          returns 1 if a == b, 0 otherwise
00046 //
00047 // int operator != (const sint & a, const BitInt & b)
00048 //          returns 1 if a != b, 0 otherwise
00049 //
00050 // int operator < (const sint & a, const sint & b)
00051 //          returns 1 if a < b, 0 otherwise
00052 //
00053 // int operator <= (const sint & a, const sint & b)
00054 //          returns 1 if a <= b, 0 otherwise
00055 //
00056 // int operator > (const sint & a, const sint & b)
00057 //          returns 1 if a > b, 0 otherwise
00058 //
00059 // int operator >= (const sint & a, const sint & b)
00060 //          returns 1 if a >= b, 0 otherwise
00061 //
00062 //
00063 //  ***** I/O operators:
00064 //
00065 //  ostream & operator << (ostream & os, const sint & b)
00066 //        stream operator to print value
00067 //
00068 
00069 class sint
00070 {
00071   public:
00072     
00073     sint();                  // default constructor, value = 0
00074     sint(int);               // assign an integer value
00075     //sint(const string &);    // assign a string 
00076     sint(const sint &);    // copy constructor
00077     ~sint();                 // destructor
00078 
00079     // operators: arithmetic, relational
00080 
00081     void operator += (const sint &);
00082     void operator *= (const sint &);
00083     sint & operator = (const sint &);
00084 
00085     friend ostream & operator <<(ostream &, const sint &);
00086     friend int operator == (const sint &, const sint &);
00087     friend int operator < (const sint &, const sint &);
00088   private:
00089     static const int INTDIGITS;
00090     void grow(int size);
00091     int capacity;
00092     int numDigits;
00093     int *digits;
00094 };
00095 
00096 
00097 sint operator +(const sint &, const sint &);
00098 sint operator *(const sint &, const sint &);
00099 int operator != (const sint & a, const sint & b);
00100 int operator > (const sint &, const sint &);
00101 int operator >= (const sint &, const sint &);
00102 int operator <= (const sint &, const sint &);
00103 
00104 
00105 #endif   // BIGINT_H not defined

Generated at Sun Feb 24 09:57:16 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001