Vaucanson 1.4
|
00001 // q_number.hh: this file is part of the Vaucanson project. 00002 // 00003 // Vaucanson, a generic library for finite state machines. 00004 // 00005 // Copyright (C) 2011 The Vaucanson Group. 00006 // 00007 // This program is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 00010 // of the License, or (at your option) any later version. 00011 // 00012 // The complete GNU General Public Licence Notice can be found as the 00013 // `COPYING' file in the root directory. 00014 // 00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file. 00016 // 00017 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_Q_NUMBER_HH 00018 # define VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_Q_NUMBER_HH 00019 00020 #include <iostream> 00021 /* @{ *//* @{ */ 00035 namespace vcsn 00036 { 00037 /* @{ */ 00039 namespace algebra 00040 {/* @{ */ 00042 00057 template<typename IntType> 00058 class TRationalNumber 00059 { 00060 public: 00064 inline 00065 TRationalNumber (); 00067 inline 00068 TRationalNumber (const IntType num); 00070 inline 00071 TRationalNumber (const IntType num, const IntType den); 00073 inline 00074 TRationalNumber (const TRationalNumber<IntType>& nb); 00075 // Object destructor. 00076 inline 00077 ~TRationalNumber (); 00079 public: 00083 inline 00084 TRationalNumber& set (const IntType num, const IntType den = 1); 00089 inline 00090 IntType num_get () const; 00092 inline 00093 IntType den_get () const; 00095 inline 00096 std::ostream& print (std::ostream& ostr) const; 00097 00099 public: 00103 inline 00104 TRationalNumber<IntType> operator+ (const TRationalNumber<IntType>& nb) const; 00105 inline 00106 TRationalNumber<IntType> operator- (const TRationalNumber<IntType>& nb) const; 00107 inline 00108 TRationalNumber<IntType> operator- () const; 00109 inline 00110 TRationalNumber<IntType> operator* (const TRationalNumber<IntType>& nb) const; 00111 inline 00112 TRationalNumber<IntType> operator/ (const TRationalNumber<IntType>& nb) const; 00113 00114 inline 00115 TRationalNumber<IntType>& operator+= (const TRationalNumber<IntType>& nb); 00116 inline 00117 TRationalNumber<IntType>& operator-= (const TRationalNumber<IntType>& nb); 00118 inline 00119 TRationalNumber<IntType>& operator*= (const TRationalNumber<IntType>& nb); 00120 inline 00121 TRationalNumber<IntType>& operator/= (const TRationalNumber<IntType>& nb); 00122 00124 inline 00125 bool operator== (const TRationalNumber<IntType>& nb) const; 00126 inline 00127 bool operator!= (const TRationalNumber<IntType>& nb) const; 00128 inline 00129 bool operator< (const TRationalNumber<IntType>& nb) const; 00130 inline 00131 bool operator<= (const TRationalNumber<IntType>& nb) const; 00132 inline 00133 bool operator> (const TRationalNumber<IntType>& nb) const; 00134 inline 00135 bool operator>= (const TRationalNumber<IntType>& nb) const; 00136 00137 // @} 00138 00142 // operator int () const; 00143 //operator float () const; 00144 inline 00145 operator double () const; 00146 00148 inline 00149 IntType to_integer () const; 00150 inline 00151 float to_float () const; 00152 inline 00153 double to_double () const; 00155 protected: 00158 00166 inline void set_rational (); 00167 inline void set_rational (const IntType num, const IntType den); 00168 inline void set_unsafe_rational (const IntType num, const IntType den); 00170 protected: 00174 IntType num_; 00176 IntType den_; 00178 }; // TRationalNumber<IntType> 00179 00180 template<typename IntType> 00181 inline 00182 std::ostream& operator<< (std::ostream&, const TRationalNumber<IntType>&); 00183 00184 template<typename IntType> 00185 inline 00186 std::istream& operator>> (std::istream&, TRationalNumber<IntType>&); 00187 00188 typedef TRationalNumber<long long> RationalNumber; 00189 00191 } // !algebra 00192 00194 } // !vcsn 00195 00196 00197 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB 00198 # include <vaucanson/algebra/implementation/semiring/q_number.hxx> 00199 # endif // VCSN_USE_INTERFACE_ONLY 00200 00201 00202 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_Q_NUMBER_HH