00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00026 #ifndef __PICINFO_RATIONAL_HEADER_INCLUDED__
00027 #define __PICINFO_RATIONAL_HEADER_INCLUDED__
00028
00029 #include <ostream>
00030
00031 namespace picinfo {
00032
00038 template <typename T>
00039 struct Rational
00040 {
00041 T numerator ;
00042 T dominator ;
00043
00044 operator double( ) const
00045 {
00046 return static_cast<double>( numerator ) /
00047 static_cast<double>( dominator ) ;
00048 }
00049
00050 operator uint32_t( ) const
00051 {
00052 return numerator / dominator ;
00053 }
00054
00055 operator int32_t( ) const
00056 {
00057 return numerator / dominator ;
00058 }
00059
00060 operator uint16_t( ) const
00061 {
00062 return static_cast<uint16_t>(numerator / dominator) ;
00063 }
00064
00065 operator int16_t( ) const
00066 {
00067 return static_cast<int16_t>(numerator / dominator) ;
00068 }
00069
00070 operator int8_t( ) const
00071 {
00072 return static_cast<uint8_t>( numerator / dominator ) ;
00073 }
00074
00075 operator uint8_t( ) const
00076 {
00077 return static_cast<uint8_t>( numerator / dominator ) ;
00078 }
00079
00080 Rational( T num = 0, T dom = 1 ) : numerator( num ), dominator( dom )
00081 {
00082 }
00083 } ;
00084
00085 template <typename T>
00086 std::ostream& operator<<( std::ostream& os, const Rational<T>& rat )
00087 {
00088 return os << rat.numerator << '/' << rat.dominator ;
00089 }
00090
00091 }
00092
00093 #endif