00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __TRational__
00023 #define __TRational__
00024
00025 #include <string>
00026 #include "exports.h"
00027
00028 using namespace std;
00029
00034 class EXP TRational {
00035
00036 private:
00037 long int fNumerator;
00038 long int fDenominator;
00039
00041 long int gcd(long int a, long int b);
00042
00043 public:
00044 TRational(long int num = 0, long int denom = 1);
00045 TRational(const TRational& d);
00046 TRational(const string &str);
00047
00048 long int getNumerator() const { return fNumerator; }
00049 long int getDenominator() const { return fDenominator; }
00050 void setNumerator(long int d) { fNumerator = d; }
00051 void setDenominator(long int d) { fDenominator = d; }
00052 void set( long int n, long int d ) { fNumerator = n; fDenominator = d; }
00053
00054 TRational operator +(const TRational &dur) const;
00055 TRational operator -(const TRational &dur) const;
00057 TRational operator *(const TRational &dur) const;
00058 TRational operator /(const TRational &dur) const;
00059
00060
00061 TRational operator *(int num) const;
00062 TRational operator /(int num) const;
00063
00064 TRational& operator +=(const TRational &dur);
00065 TRational& operator -=(const TRational &dur);
00067 TRational& operator *=(const TRational &dur);
00068 TRational& operator /=(const TRational &dur);
00069
00070
00071 TRational& operator *=(long int num) { fNumerator *= num; return *this; }
00072 TRational& operator /=(long int num) { fDenominator *= num; return *this; }
00073
00074 TRational& operator =(const TRational& dur);
00075
00076 bool operator >(const TRational &dur) const;
00077 bool operator >=(const TRational &dur) const {return ! (*this < dur);}
00078 bool operator <(const TRational &dur) const;
00079 bool operator <=(const TRational &dur) const {return ! (*this > dur);}
00080
00081 bool operator ==(const TRational &dur) const;
00082 bool operator !=(const TRational &dur) const {return ! (*this == dur);}
00083
00084 bool operator > (double num) const;
00085 bool operator >=(double num) const;
00086 bool operator < (double num) const;
00087 bool operator <=(double num) const;
00088 bool operator ==(double) const;
00089
00090
00091 void rationalise();
00092
00093 operator string () const;
00094 operator double () const;
00095 operator float () const;
00096 operator int () const;
00097
00098 virtual string toString() const;
00099 double toDouble() const;
00100 float toFloat() const;
00101 int toInt() const;
00102 };
00103
00104 #endif
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115