CRational & CRational::operator+=(const CRational & other) { m_numerator = GetNumerator() * other.GetDenominator() + GetDenominator() * other.GetNumerator(); m_denominator = GetDenominator() * other.GetDenominator(); Normalize(); return *this; }
/* Check whether the number equals 0 */ int EqualsZero(VyNumber** num){ /* Use ANDS and ORS to check */ if((num[0]->type == INT && GetInt(num) == 0) ||(num[0]->type == REAL && GetDouble(num) == 0) ||(num[0]->type == COMPLEX && EqualsZero(GetReal(num)) && EqualsZero(GetImaginary(num))) ||(num[0]->type == RATIO && GetNumerator(num) == 0)){ return 1; } else { return 0; } }
CRational const CRational::operator-() const { return CRational(-GetNumerator(), GetDenominator()); }
double CRational::ToDouble() const { return static_cast<double>(GetNumerator()) / static_cast<double>(GetDenominator()); }