d02 ex02 ajout protection division par 0

This commit is contained in:
Hugo LAMY
2022-02-18 18:22:46 +01:00
parent bd83d90b5f
commit 46fd7395b2

View File

@@ -141,6 +141,9 @@ Fixed Fixed::operator* ( Fixed const & rhs ) const {
} }
Fixed Fixed::operator/ ( Fixed const & rhs ) const { Fixed Fixed::operator/ ( Fixed const & rhs ) const {
Fixed result(*this); Fixed result(*this);
if (rhs.value == 0)
std::cout << "impossible division by 0\n";
else
result._value = (long)(result._value << Fixed::_frac) / rhs._value; result._value = (long)(result._value << Fixed::_frac) / rhs._value;
return result; return result;
} }