longint.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 //  Copyright (c) 2006 by Rafael Ostertag
00004 //
00005 //  This program is free software; you can redistribute it and/or modify
00006 //  it under the terms of the GNU General Public License as published by
00007 //  the Free Software Foundation; either version 2 of the License, or
00008 //  (at your option) any later version.
00009 //
00010 //  This program is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //  GNU General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU General Public License
00016 //  along with this program; if not, write to the Free Software
00017 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 //
00019 //
00020 // $Id: longint.h,v 1.15 2006/12/28 19:01:25 rafi Exp $
00021 //
00022 
00032 #ifndef _LONGINT_H
00033 #define _LONGINT_H
00034 
00035 #ifdef HAVE_CONFIG_H
00036 #include "config.h"
00037 #endif
00038 
00039 #include <list>
00040 #include <string>
00041 
00042 #include "casexception.h"
00043 #include "casnumeric.h"
00044 
00057 class LongInt : public CASNumeric {
00058     private:
00064         enum {
00072             part_len = 3,
00079             fmt_len = 80
00080     };
00081 
00087         std::list<unsigned int> lst;
00088 
00094         LongInt *div_remainder;
00102         unsigned long frontpartlength() const;
00106         void str2longint ( const char* str_num );
00110         void num2longint ( const signed long num );
00114         void longint2str ( char* s, unsigned long size ) const;
00118         void stripzeros();
00122         void setzero();
00123 
00124     public:
00128         LongInt ( signed long l = 0 );
00132         LongInt ( const char *s );
00136         LongInt ( const std::string &s );
00140         LongInt ( const LongInt &r );
00144         ~LongInt();
00145 
00149         CASObject* Clone() const;
00158         inline CASType GetType() const {
00159             return CT_LONGINT;
00160         }
00164         void Get ( char *s, unsigned long size ) const;
00168         void Get ( std::string &s ) const;
00172         unsigned long Length() const;
00176         void Print() const;
00180         CASObject* Invert() const;
00184         CASObject* Absolute() const;
00188         bool IsZero() const;
00192         bool IsOne() const;
00196         CASObject* Add ( const CASObject* addend ) const;
00200         CASObject* Subtract ( const CASObject* sub ) const;
00204         CASObject* Multiply ( const CASObject* fact ) const;
00208         CASObject* Divide ( const CASObject* divisor ) const;
00212         CASObject* Power ( const CASObject* exp ) const;
00216         CASObject* Modulo ( const CASObject* divisor ) const;
00221         CASObject* GCD ( const CASObject* i ) const;
00226         bool IsEqual ( const CASObject* o ) const;
00231         bool IsLT ( const CASObject* o ) const;
00236         bool IsGT ( const CASObject* o ) const;
00241         bool IsSimilar ( const CASObject* o ) const;
00245         CASObject* Evaluate() const;
00259         inline CASObject* SortWeight() const {
00260             return Clone();
00261         }
00271         inline void Sort() {
00272             meta.SetSorted();
00273         }
00283         inline bool IsPureNumerical() const { return meta.IsPureNumerical(); }
00284 
00288         void Get ( char **s ) const throw ( EInvArg, EUninitializedPtr );
00292         LongInt Pow ( const LongInt &exp ) const;
00296         LongInt Pow ( unsigned long exp ) const;
00300         LongInt FractionalPart ( const LongInt &r ) const;
00304         LongInt FractionalPart ( signed long r ) const;
00305 
00309         LongInt& operator= ( const LongInt &r );
00313         LongInt& operator= ( const signed long &r );
00317         LongInt& operator+= ( const LongInt &r );
00321         LongInt& operator+= ( const signed long &r );
00325         LongInt& operator-= ( const LongInt &r );
00329         LongInt& operator-= ( const signed long &r );
00333         LongInt& operator*= ( const LongInt &r );
00337         LongInt& operator*= ( const signed long &r );
00341         LongInt& operator/= ( const LongInt &r );
00345         LongInt& operator/= ( const signed long &r );
00349         LongInt& operator%= ( const LongInt &r );
00353         LongInt& operator%= ( const signed long &r );
00357         const LongInt operator+ ( const LongInt &r ) const;
00361         const LongInt operator+ ( const long &r ) const;
00365         const LongInt operator* ( const LongInt &r ) const;
00369         const LongInt operator* ( const long &r ) const;
00373         const LongInt operator- ( const LongInt &r ) const;
00377         const LongInt operator- ( const long &r ) const;
00381         const LongInt operator/ ( const LongInt &r ) const;
00385         const LongInt operator/ ( const long &r ) const;
00389         const LongInt operator% ( const LongInt &r ) const;
00393         const LongInt operator% ( const long &r ) const;
00397         const bool operator== ( const LongInt &r ) const;
00401         const bool operator== ( const long &r ) const;
00405         const bool operator!= ( const LongInt &r ) const;
00409         const bool operator!= ( const long &r ) const;
00413         const bool operator< ( const LongInt &r ) const;
00417         const bool operator< ( const long &r ) const;
00421         const bool operator> ( const LongInt &r ) const;
00425         const bool operator> ( const long &r ) const;
00429         const bool operator>= ( const LongInt &r ) const;
00433         const bool operator>= ( const long &r ) const;
00437         const bool operator<= ( const LongInt &r ) const;
00441         const bool operator<= ( const long &r ) const;
00445         const LongInt operator<< ( const signed long &r ) const;
00449         const LongInt operator++();
00453         const LongInt operator++ ( int );
00457         const LongInt operator--();
00461         const LongInt operator-- ( int );
00462 
00463         friend class CASConvert;
00464 };
00465 
00470 #endif /* _LONGINT_H */

Generated on Sun Dec 31 01:57:27 2006 for ECAS by  doxygen 1.4.7