#include "Number.hh" #include "NumberRep.hh" #include "Integer.hh" #include "Long.hh" //#include "LargeInt.hh" #include "Complex.hh" //#include "Imaginary.hh" Number::Number( ) { rep = new Integer ( ); rep->count = 1; } Number::Number( const Number& n ) { rep = n.rep; rep->count++; } Number::Number( const int value ) { rep = new Integer( value ); rep->count = 1; } Number::Number( const long value ) { rep = new Long( value ); rep->count = 1; } Number::Number( const char* value ) { rep = new LargeInt( value ); rep->count = 1; } Number::Number( const int rValue, const int iValue ) { if( rValue == 0 ) rep = new Imaginary( new Integer( iValue ) ); else rep = new Complex( new Integer( rValue ), new Integer( iValue ) ); rep->count = 1; } Number::Number( const int rValue, const long iValue ) { // falta redondeo if( rValue == 0 ) rep = new Imaginary( new Long( iValue ) ); else rep = new Complex( new Integer( rValue ), new Long( iValue ) ); rep->count = 1; } Number::Number( const int rValue, const char* iValue ) { // falta redondeo if( rValue == 0 ) rep = new Imaginary( new LargeInt( iValue ) ); else rep = new Complex( new Integer( rValue ), new LargeInt( iValue ) ); rep->count = 1; } Number::Number( const long rValue, const int iValue ) { // falta redondeo if( rValue == 0 ) rep = new Imaginary( new Integer( iValue ) ); else rep = new Complex( new Long( rValue ), new Integer( iValue ) ); rep->count = 1; } Number::Number( const long rValue, const long iValue ) { // falta redondeo if( rValue == 0 ) rep = new Imaginary( new Integer( iValue ) ); else rep = new Complex( new Long( rValue ), new Integer( iValue ) ); rep->count = 1; } Number::Number( const long rValue, const char* iValue ) { // falta redondeo if( rValue == 0 ) rep = new Imaginary( new LargeInt( iValue ) ); else rep = new Complex( new Long( rValue ), new LargeInt( iValue ) ); rep->count = 1; } Number::Number( const char* rValue, const int iValue ) { // falta redondeo LargeInt* lI = new LargeInt( rValue ); if( *lI == 0 ) rep = new Imaginary( new Integer( iValue ) ); else rep = new Complex( lI, new Integer( iValue ) ); rep->count = 1; } Number::Number( const char* rValue, const long iValue ) { // falta redondeo LargeInt* lI = new LargeInt( rValue ); if( *lI == 0 ) rep = new Imaginary( new Long( iValue ) ); else rep = new Complex( lI, new Long( iValue ) ); rep->count = 1; } Number::Number( const char* rValue, const char* iValue ) { // falta redondeo LargeInt* lI = new LargeInt( rValue ); if( *lI == 0 ) rep = new Imaginary( new LargeInt( iValue ) ); else rep = new Complex( lI, new LargeInt( iValue ) ); rep->count = 1; } Number& Number::operator= ( const Number& n ) { n.rep->count ++; rep->count--; if( rep->count == 0 ) delete rep; rep = n.rep; } Number::~Number( ) { rep->count--; if( rep->count == 0 ) delete rep; } Number Number::operator+ ( const Number& n ) const { return Number( (*rep) + *(n.rep) ); } Number Number::operator- ( const Number& n ) const { return Number( (*rep) - *(n.rep) ); } Number Number::operator- ( ) const { return Number( - *rep ); } // private: Number::Number( NumberRep* rep ) { this->rep = rep; rep->count = 1; }