d02 ex02 errors comparisons and _value

This commit is contained in:
Hugo LAMY
2022-02-18 18:40:18 +01:00
parent 46fd7395b2
commit ab0a2c4184
6 changed files with 23 additions and 13 deletions

View File

@@ -113,13 +113,13 @@ bool Fixed::operator> (Fixed const & rhs) const {
return rhs < *this;
}
bool Fixed::operator<=(Fixed const & rhs) const {
return !(rhs > *this);
return !(*this > rhs);
}
bool Fixed::operator>=(Fixed const & rhs) const {
return !(rhs < *this);
return !(*this < rhs);
}
bool Fixed::operator==(Fixed const & rhs) const {
return this->toFloat() == rhs.toFloat();
return this->_value == rhs._value;
}
bool Fixed::operator!=(Fixed const & rhs) const {
return !(*this == rhs);
@@ -141,8 +141,8 @@ Fixed Fixed::operator* ( Fixed const & rhs ) const {
}
Fixed Fixed::operator/ ( Fixed const & rhs ) const {
Fixed result(*this);
if (rhs.value == 0)
std::cout << "impossible division by 0\n";
if (rhs._value == 0)
std::cout << "!impossible division by 0¡";
else
result._value = (long)(result._value << Fixed::_frac) / rhs._value;
return result;

View File

@@ -30,14 +30,14 @@ int main( void ) {
// ">"
std::cout << "\n" COLOR "operator >"" RESET " RESET "\n";
std::cout << "e = greater of (c, d) : e == " << (e = (c > d) ? c : d) << '\n';
std::cout << COLOR2 "e:" << e << " c:" << c << " d:" << d << RESET "\n";
std::cout << "e = greater of (c, d) : e == " << (e = (c > d) ? c : d) << '\n';
std::cout << "e > c ? : " << (e > c) << '\n';
std::cout << "e > d ? : " << (e > d) << '\n';
// "<"
std::cout << "\n" COLOR "operator <" RESET "\n";
std::cout << "e = smaller of (c, d) : e == " << (e = (c < d) ? c : d) << '\n';
std::cout << COLOR2 "e:" << e << " c:" << c << " d:" << d << RESET "\n";
std::cout << "e = smaller of (c, d) : e == " << (e = (c < d) ? c : d) << '\n';
std::cout << "e < c ? : " << (e < c) << '\n';
std::cout << "e < d ? : " << (e < d) << '\n';
// "<="
@@ -98,6 +98,10 @@ int main( void ) {
d = Fixed(10);
std::cout << COLOR2 "e:" << e << " c:" << c << " d:" << d << RESET "\n";
std::cout << "e = c / d ? : " << (e = c / d) << '\n';
c = Fixed(6);
d = Fixed(0);
std::cout << COLOR2 "e:" << e << " c:" << c << " d:" << d << RESET "\n";
std::cout << "e = c / d ? : " << (e = c / d) << '\n';
// "+ - * /"
std::cout << "\n" COLOR "operator + - * /" RESET "\n";
Fixed g;
@@ -111,22 +115,18 @@ int main( void ) {
// "++x"
std::cout << "\n" COLOR "operator ++o" RESET "\n";
e = Fixed(2);
std::cout << "e : " << e << '\n';
std::cout << COLOR2 "e:" << e << RESET "\n";
std::cout << "++e : " << ++e << " ; e : " << e << '\n';
// "--x"
std::cout << "\n" COLOR "operator --o" RESET "\n";
std::cout << "e : " << e << '\n';
std::cout << COLOR2 "e:" << e << RESET "\n";
std::cout << "--e : " << --e << " ; e : " << e << '\n';
// "x++"
std::cout << "\n" COLOR "operator o++" RESET "\n";
std::cout << "e : " << e << '\n';
std::cout << COLOR2 "e:" << e << RESET "\n";
std::cout << "e++ : " << e++ << " ; e : " << e << '\n';
// "x--"
std::cout << "\n" COLOR "operator o--" RESET "\n";
std::cout << "e : " << e << '\n';
std::cout << COLOR2 "e:" << e << RESET "\n";
std::cout << "e-- : " << e-- << " ; e : " << e << '\n';

Binary file not shown.