32template<
typename TYP =
int>
42 CFractionT(TYP num, TYP den) : m_numerator(num), m_denominator(den)
51 void Set(TYP num, TYP den)
64 m_numerator = other.m_numerator;
65 m_denominator = other.m_denominator;
78 TYP t1 = m_numerator * t.m_denominator;
79 TYP t2 = t.m_numerator * m_denominator;
84 return (t1 > t2) ? 1 : -1;
94 if ( m_denominator == other.m_denominator )
96 m_numerator += other.m_numerator;
100 m_denominator *= other.m_denominator;
101 m_numerator *= other.m_denominator;
102 m_numerator += other.m_numerator * other.m_denominator;
114 if ( m_denominator == other.m_denominator )
116 m_numerator -= other.m_numerator;
120 m_denominator *= other.m_denominator;
121 m_numerator *= other.m_denominator;
122 m_numerator -= other.m_numerator * other.m_denominator;
134 m_numerator *= other.m_numerator;
135 m_denominator *= other.m_denominator;
157 m_numerator *= other.m_denominator;
158 m_denominator *= other.m_numerator;
169 m_denominator *= val;
179 m_numerator = -m_numerator;
266 return m_denominator;
276 double r = m_numerator;
277 return r / m_denominator;
287 TYP r = ms_gcd(m_numerator, m_denominator);
303 static TYP ms_gcd(TYP m, TYP n)
305 if ( 0 == m || 0 == n )
316 (m > n) ? (m -= n) : (n -= m);
322 static TYP ms_lcm(TYP m, TYP n)
324 if ( 0 == m || 0 == n )
332 return ((m / ms_gcd(m, n)) * n);
337 friend class CFractionTest;
TYP GetDenominator(void) const
[取得] 分母取得.
CFractionT operator/(TYP val) const
[計算] 除算.
CFractionT operator+(const CFractionT &other) const
[計算] 加算.
virtual INT_PTR Compare(const CFractionT &t) const
[確認] 比較
CFractionT operator*(const CFractionT &other) const
[計算] 乗算.
CFractionT & operator/=(const CFractionT &other)
[代入] 除算代入.
CFractionT operator-(const CFractionT &other) const
[計算] 減算.
CFractionT & LeastCommonDivisor(void)
[変換] 最小公倍.
CFractionT & operator*=(TYP val)
[代入] 乗算代入.
CFractionT & operator=(const CFractionT &other)
[代入] 代入.
TYP GetNumerator(void) const
[取得] 分子取得.
CFractionT & operator/=(TYP val)
[代入] 除算代入.
CFractionT operator*(TYP val) const
[計算] 乗算.
void Set(TYP num, TYP den)
[設定] 値設定.
CFractionT & operator+=(const CFractionT &other)
[代入] 加算代入.
CFractionT & operator-(void)
[設定] マイナス化.
CFractionT operator/(const CFractionT &other) const
[計算] 除算.
double Get(void) const
[取得] 実数取得.
CFractionT(TYP num, TYP den)
コンストラクタ
CFractionT & operator-=(const CFractionT &other)
[代入] 減算代入.
CFractionT & operator*=(const CFractionT &other)
[代入] 乗算代入.
void Swap(T &t1, T &t2)
[変換] スワッパー.
CFractionT< int > CFraction
分数管理.