コード例 #1
0
ファイル: Rational.cpp プロジェクト: SashaOcheev/OOP
CRational & CRational::operator+=(const CRational & other)
{
	m_numerator = GetNumerator() * other.GetDenominator() + GetDenominator() * other.GetNumerator();
	m_denominator = GetDenominator() * other.GetDenominator();
	Normalize();
	return *this;
}
コード例 #2
0
ファイル: Arithmetic.c プロジェクト: BillyBuggy/experiments
/* 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
ファイル: Rational.cpp プロジェクト: SashaOcheev/OOP
CRational const CRational::operator-() const
{
	return CRational(-GetNumerator(), GetDenominator());
}
コード例 #4
0
ファイル: Rational.cpp プロジェクト: SashaOcheev/OOP
double CRational::ToDouble() const
{
	return static_cast<double>(GetNumerator()) / static_cast<double>(GetDenominator());
}