// call by value - non-member function RationalNumber operator/(const RationalNumber& one, const RationalNumber& two) { if (one.isNaN() || two.isNaN()) { RationalNumber r; return r; } RationalNumber r(one.nomi() * two.deno(), one.deno() * two.nomi()); return r; }
// call by value RationalNumber RationalNumber::operator-(const RationalNumber& other) const { if (other.isNaN()) return RationalNumber(*this); RationalNumber r(*this); r -= other; r.normalize(); return r; }
bool RationalNumber::operator==(const RationalNumber& other) const { if (other.isNaN()) return false; signed short int a1 = nomi() * other.deno(); signed short int b1 = deno() * other.deno(); signed short int a2 = other.nomi() * deno(); signed short int b2 = other.deno() * deno(); return (a1 == a2 && b1 == b2); }
// call by value RationalNumber RationalNumber::operator+(const RationalNumber& other) const { if (other.isNaN()) return RationalNumber(*this); /* RationalNumber result(nomi() * other.deno() + other.nomi() * deno(), deno() * other.deno()); return result; */ RationalNumber r(*this); r += other; r.normalize(); return r; }
bool RationalNumber::operator||(const RationalNumber& other) const { if (other.isNaN()) return nomi() > 0; return nomi() > 0 || other.nomi() > 0; }
bool RationalNumber::operator&&(const RationalNumber& other) const { if (other.isNaN()) return false; return nomi() > 0 && other.nomi() > 0; }
bool RationalNumber::operator>=(const RationalNumber& other) const { if (other.isNaN()) return false; return *this > other || *this == other; }
bool RationalNumber::operator>(const RationalNumber& other) const { if (other.isNaN()) return false; return ((nomi() * other.deno()) * (deno() * other.deno())) > ((other.nomi() * deno()) * (other.deno() * deno())); }
bool RationalNumber::operator!=(const RationalNumber& other) const { if (other.isNaN()) return false; return !(*this == other); }