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 
00088   enum NumType {SpecialType, IntegerType, FractionType, FloatType};
00089 
00107   enum ErrorType {UndefinedNumber, Infinity, MinusInfinity};
00108 
00109   KNumber(signed int num = 0);
00110   KNumber(unsigned int num);  
00111   KNumber(signed long int num);
00112   KNumber(unsigned long int num);
00113   KNumber(unsigned long long int num);
00114 
00115   KNumber(double num);
00116 
00117   KNumber(KNumber const & num);
00118   
00119   KNumber(QString const & num);
00120   
00121   ~KNumber()
00122   {
00123     delete _num;
00124   }
00125   
00126   KNumber const & operator=(KNumber const & num);
00127 
00131   NumType type(void) const;
00132 
00143   static void setDefaultFloatOutput(bool flag);
00144 
00152   static void setDefaultFractionalInput(bool flag);
00153 
00159   static void setDefaultFloatPrecision(unsigned int prec);
00160 
00169   static void setSplitoffIntegerForFractionOutput(bool flag);
00170 
00183   QString const toQString(int width = -1, int prec = -1) const;
00184   
00192   KNumber const abs(void) const;
00193 
00205   KNumber const sqrt(void) const;
00206 
00220   KNumber const cbrt(void) const;
00221 
00229   KNumber const integerPart(void) const;
00230 
00231   KNumber const power(KNumber const &exp) const;
00232 
00233   KNumber const operator+(KNumber const & arg2) const;
00234   KNumber const operator -(void) const;
00235   KNumber const operator-(KNumber const & arg2) 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 
00240   KNumber const operator&(KNumber const & arg2) const;
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 
00245   operator bool(void) const;
00246   operator signed long int(void) const;
00247   operator unsigned long int(void) const;
00248   operator unsigned long long int(void) const;
00249   operator double(void) const;
00250 
00251   bool const operator==(KNumber const & arg2) const
00252   { return (compare(arg2) == 0); }
00253 
00254   bool const operator!=(KNumber const & arg2) const
00255   { return (compare(arg2) != 0); }
00256 
00257   bool const operator>(KNumber const & arg2) const
00258   { return (compare(arg2) > 0); }
00259 
00260   bool const operator<(KNumber const & arg2) const
00261   { return (compare(arg2) < 0); }
00262 
00263   bool const operator>=(KNumber const & arg2) const
00264   { return (compare(arg2) >= 0); }
00265 
00266   bool const operator<=(KNumber const & arg2) const
00267   { return (compare(arg2) <= 0); }
00268 
00269   KNumber & operator +=(KNumber const &arg);
00270   KNumber & operator -=(KNumber const &arg);
00271 
00272 
00273   //KNumber const toFloat(void) const;
00274   
00275   
00276   
00277   
00278  private:
00279   void simplifyRational(void);
00280   int const compare(KNumber const & arg2) const;
00281   
00282   _knumber *_num;
00283   static bool _float_output;
00284   static bool _fraction_input;
00285   static bool _splitoffinteger_output;
00286 };
00287 
00288 
00289 
00290 #endif // _KNUMBER_H
KDE Home | KDE Accessibility Home | Description of Access Keys