knumber.h

00001 // -*- c-basic-offset: 2 -*-
00002 /* This file is part of the KDE libraries
00003     Copyright (C) 2005 Klaus Niederkrueger <kniederk@math.uni-koeln.de>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library 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 GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 #ifndef _KNUMBER_H
00021 #define _KNUMBER_H
00022 
00023 #include <gmp.h>
00024 
00025 #include <kdelibs_export.h>
00026 
00027 #include "knumber_priv.h"
00028 
00029 class QString;
00030 
00065 class KDE_EXPORT KNumber
00066 {
00067  public:
00068   static KNumber const Zero;
00069   static KNumber const One;
00070   static KNumber const MinusOne;
00071   static KNumber const Pi;
00072   static KNumber const Euler;
00073   static KNumber const NotDefined;
00074 
00089   enum NumType {SpecialType, IntegerType, FractionType, FloatType};
00090 
00108   enum ErrorType {UndefinedNumber, Infinity, MinusInfinity};
00109 
00110   KNumber(signed int num = 0);
00111   KNumber(unsigned int num);  
00112   KNumber(signed long int num);
00113   KNumber(unsigned long int num);
00114   KNumber(unsigned long long int num);
00115 
00116   KNumber(double num);
00117 
00118   KNumber(KNumber const & num);
00119   
00120   KNumber(QString const & num);
00121   
00122   ~KNumber()
00123   {
00124     delete _num;
00125   }
00126   
00127   KNumber const & operator=(KNumber const & num);
00128 
00132   NumType type(void) const;
00133 
00144   static void setDefaultFloatOutput(bool flag);
00145 
00153   static void setDefaultFractionalInput(bool flag);
00154 
00160   static void setDefaultFloatPrecision(unsigned int prec);
00161 
00170   static void setSplitoffIntegerForFractionOutput(bool flag);
00171 
00184   QString const toQString(int width = -1, int prec = -1) const;
00185   
00193   KNumber const abs(void) const;
00194 
00206   KNumber const sqrt(void) const;
00207 
00221   KNumber const cbrt(void) const;
00222 
00230   KNumber const integerPart(void) const;
00231 
00232   KNumber const power(KNumber const &exp) const;
00233 
00234   KNumber const operator+(KNumber const & arg2) const;
00235   KNumber const operator -(void) const;
00236   KNumber const operator-(KNumber const & arg2) const;
00237   KNumber const operator*(KNumber const & arg2) const;
00238   KNumber const operator/(KNumber const & arg2) const;
00239   KNumber const operator%(KNumber const & arg2) const;
00240 
00241   KNumber const operator&(KNumber const & arg2) const;
00242   KNumber const operator|(KNumber const & arg2) const;
00243   KNumber const operator<<(KNumber const & arg2) const;
00244   KNumber const operator>>(KNumber const & arg2) const;
00245 
00246   operator bool(void) const;
00247   operator signed long int(void) const;
00248   operator unsigned long int(void) const;
00249   operator unsigned long long int(void) const;
00250   operator double(void) const;
00251 
00252   bool const operator==(KNumber const & arg2) const
00253   { return (compare(arg2) == 0); }
00254 
00255   bool const operator!=(KNumber const & arg2) const
00256   { return (compare(arg2) != 0); }
00257 
00258   bool const operator>(KNumber const & arg2) const
00259   { return (compare(arg2) > 0); }
00260 
00261   bool const operator<(KNumber const & arg2) const
00262   { return (compare(arg2) < 0); }
00263 
00264   bool const operator>=(KNumber const & arg2) const
00265   { return (compare(arg2) >= 0); }
00266 
00267   bool const operator<=(KNumber const & arg2) const
00268   { return (compare(arg2) <= 0); }
00269 
00270   KNumber & operator +=(KNumber const &arg);
00271   KNumber & operator -=(KNumber const &arg);
00272 
00273 
00274   //KNumber const toFloat(void) const;
00275   
00276   
00277   
00278   
00279  private:
00280   void simplifyRational(void);
00281   int const compare(KNumber const & arg2) const;
00282   
00283   _knumber *_num;
00284   static bool _float_output;
00285   static bool _fraction_input;
00286   static bool _splitoffinteger_output;
00287 };
00288 
00289 
00290 
00291 #endif // _KNUMBER_H
KDE Home | KDE Accessibility Home | Description of Access Keys