Wm4TRational.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef WM4TRATIONAL_H
00018 #define WM4TRATIONAL_H
00019
00020 #include "Wm4FoundationLIB.h"
00021 #include "Wm4TInteger.h"
00022
00023 namespace Wm4
00024 {
00025
00026
00027 template <int N>
00028 class TRational
00029 {
00030 public:
00031
00032 TRational ();
00033 TRational (const TRational& rkR);
00034 TRational (const TInteger<N>& rkNumer);
00035 TRational (const TInteger<N>& rkNumer, const TInteger<N>& rkDenom);
00036
00037
00038 TRational (int iNumer);
00039 TRational (int iNumer, int iDenom);
00040 TRational (float fValue);
00041 TRational (double dValue);
00042
00043
00044 TInteger<N>& Numer ();
00045 TInteger<N>& Denom ();
00046 const TInteger<N>& Numer () const;
00047 const TInteger<N>& Denom () const;
00048
00049
00050 TRational& operator= (const TRational& rkR);
00051
00052
00053 bool operator== (const TRational& rkR) const;
00054 bool operator!= (const TRational& rkR) const;
00055 bool operator<= (const TRational& rkR) const;
00056 bool operator< (const TRational& rkR) const;
00057 bool operator>= (const TRational& rkR) const;
00058 bool operator> (const TRational& rkR) const;
00059
00060
00061 TRational operator+ (const TRational& rkR) const;
00062 TRational operator- (const TRational& rkR) const;
00063 TRational operator* (const TRational& rkR) const;
00064 TRational operator/ (const TRational& rkR) const;
00065 TRational operator- () const;
00066
00067
00068 TRational& operator+= (const TRational& rkR);
00069 TRational& operator-= (const TRational& rkR);
00070 TRational& operator*= (const TRational& rkR);
00071 TRational& operator/= (const TRational& rkR);
00072
00073
00074 void ConvertTo (float& rfValue) const;
00075 void ConvertTo (double& rdValue) const;
00076
00077
00078 TRational Abs () const;
00079
00080 private:
00081
00082 void EliminatePowersOfTwo ();
00083
00084 static void GetPositiveFloat (const TInteger<N>& rkDenom,
00085 TInteger<N>& rkQuo, TInteger<N>& rkRem, int iBlock,
00086 unsigned int& ruiExponent, unsigned int& ruiMantissa);
00087
00088 static void GetPositiveDouble (const TInteger<N>& rkDenom,
00089 TInteger<N>& rkQuo, TInteger<N>& rkRem, int iBlock,
00090 unsigned int& ruiExponent, unsigned int& ruiMantissaHi,
00091 unsigned int& ruiMantissaLo);
00092
00093 TInteger<N> m_kNumer, m_kDenom;
00094 };
00095
00096 template <int N>
00097 TRational<N> operator+ (const TInteger<N>& rkI, const TRational<N>& rkR);
00098
00099 template <int N>
00100 TRational<N> operator- (const TInteger<N>& rkI, const TRational<N>& rkR);
00101
00102 template <int N>
00103 TRational<N> operator* (const TInteger<N>& rkI, const TRational<N>& rkR);
00104
00105 template <int N>
00106 TRational<N> operator/ (const TInteger<N>& rkI, const TRational<N>& rkR);
00107
00108 }
00109
00110 #include "Wm4TRational.inl"
00111
00112 #endif