예제 #1
0
CRational & CRational::operator+=(const CRational & other)
{
	m_numerator = GetNumerator() * other.GetDenominator() + GetDenominator() * other.GetNumerator();
	m_denominator = GetDenominator() * other.GetDenominator();
	Normalize();
	return *this;
}
예제 #2
0
/* 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;	
	}
}
예제 #3
0
CRational const CRational::operator-() const
{
	return CRational(-GetNumerator(), GetDenominator());
}
예제 #4
0
double CRational::ToDouble() const
{
	return static_cast<double>(GetNumerator()) / static_cast<double>(GetDenominator());
}