Compare commits

..

No commits in common. "4d3528ed3fa2ae57054d0e82819cff0976f487f6" and "1d752c591b4f4533d05ca05ec2b4f24fd39bdb36" have entirely different histories.

3 changed files with 33 additions and 83 deletions

View File

@ -10,7 +10,7 @@ Fixed::~Fixed()
Fixed::Fixed() Fixed::Fixed()
{ {
this->_value = 0; ths->_value = 0;
std::cout << "Default constructor called" << std::endl; std::cout << "Default constructor called" << std::endl;
} }
@ -93,52 +93,52 @@ Fixed Fixed::operator--(int)
return (tmp); return (tmp);
} }
bool Fixed::operator==(const Fixed& src) const bool Fixed::operator==(const Fixed& src)
{ {
return (this->_value == src._value); return (this->_value == src._value);
} }
bool Fixed::operator!=(const Fixed& src) const bool Fixed::operator!=(const Fixed& src)
{ {
return (this->_value != src._value); return (this->_value != src._value);
} }
bool Fixed::operator>=(const Fixed& src) const bool Fixed::operator>=(const Fixed& src)
{ {
return (this->_value >= src._value); return (this->_value >= src._value);
} }
bool Fixed::operator<=(const Fixed& src) const bool Fixed::operator<=(const Fixed& src)
{ {
return (this->_value <= src._value); return (this->_value <= src._value);
} }
bool Fixed::operator>(const Fixed& src) const bool Fixed::operator>(const Fixed& src)
{ {
return (this->_value > src._value); return (this->_value > src._value);
} }
bool Fixed::operator<(const Fixed& src) const bool Fixed::operator<(const Fixed& src)
{ {
return (this->_value < src._value); return (this->_value < src._value);
} }
Fixed Fixed::operator*(const Fixed &src) const Fixed Fixed::operator*(const Fixed &src)
{ {
return Fixed(this->toFloat() * src.toFloat()); return Fixed(this->toFloat() * src.toFloat());
} }
Fixed Fixed::operator/(const Fixed &src) const Fixed Fixed::operator/(const Fixed &src)
{ {
return Fixed(this->toFloat() / src.toFloat()); return Fixed(this->toFloat() / src.toFloat());
} }
Fixed Fixed::operator+(const Fixed &src) const Fixed Fixed::operator+(const Fixed &src)
{ {
return Fixed(this->toFloat() + src.toFloat()); return Fixed(this->toFloat() + src.toFloat());
} }
Fixed Fixed::operator-(const Fixed &src) const Fixed Fixed::operator-(const Fixed &src)
{ {
return Fixed(this->toFloat() - src.toFloat()); return Fixed(this->toFloat() - src.toFloat());
} }
@ -159,14 +159,14 @@ Fixed& Fixed::max(Fixed& f1, Fixed &f2)
const Fixed& Fixed::min(const Fixed& f1, const Fixed &f2) const Fixed& Fixed::min(const Fixed& f1, const Fixed &f2)
{ {
if (f1._value < f2._value) if (f1._value > f2._value)
return (f1); return (f1);
return (f2); return (f2);
} }
Fixed& Fixed::min(Fixed& f1, Fixed &f2) Fixed& Fixed::min(Fixed& f1, Fixed &f2)
{ {
if (f1._value < f2._value) if (f1._value > f2._value)
return (f1); return (f1);
return (f2); return (f2);
} }

View File

@ -18,17 +18,17 @@ class Fixed
Fixed &operator=(const Fixed& src); Fixed &operator=(const Fixed& src);
bool operator<(const Fixed& src) const; bool operator<(const Fixed& src);
bool operator>(const Fixed& src) const; bool operator>(const Fixed& src);
bool operator>=(const Fixed& src) const; bool operator>=(const Fixed& src);
bool operator<=(const Fixed& src) const; bool operator<=(const Fixed& src);
bool operator==(const Fixed& src) const; bool operator==(const Fixed& src);
bool operator!=(const Fixed& src) const; bool operator!=(const Fixed& src);
Fixed operator-(const Fixed& src) const; Fixed operator-(const Fixed& src);
Fixed operator+(const Fixed& src) const; Fixed operator+(const Fixed& src);
Fixed operator*(const Fixed& src) const; Fixed operator*(const Fixed& src);
Fixed operator/(const Fixed& src) const; Fixed operator/(const Fixed& src);
Fixed &operator++(); Fixed &operator++();

View File

@ -2,64 +2,14 @@
#include <iostream> #include <iostream>
int main( void ) { int main( void ) {
{ Fixed a(0);
Fixed a(0); Fixed const b( Fixed( 5.05f ) * Fixed( 2 ) );
Fixed const b( Fixed( 5.05f ) * Fixed( 2 ) ); std::cout << a << std::endl;
std::cout << a << std::endl; std::cout << ++a << std::endl;
std::cout << ++a << std::endl; std::cout << a << std::endl;
std::cout << a << std::endl; std::cout << a++ << std::endl;
std::cout << a++ << std::endl; std::cout << a << std::endl;
std::cout << a << std::endl; std::cout << b << std::endl;
std::cout << b << std::endl; std::cout << Fixed::max( a, b ) << std::endl;
std::cout << Fixed::max( a, b ) << std::endl; return 0;
}
{
// Créer deux objets Fixed pour les tests
const Fixed a(2.5f);
const Fixed b(1.3f);
std::cout << "b: " << a << std::endl;
std::cout << "a: " << b << std::endl;
// Test de l'opérateur d'addition (+)
Fixed sum = a + b;
std::cout << "Addition: " << sum << std::endl;
// Test de l'opérateur de soustraction (-)
Fixed difference = a - b;
std::cout << "Subtraction: " << difference << std::endl;
// Test de l'opérateur de multiplication (*)
Fixed product = a * b;
std::cout << "Multiplication: " << product << std::endl;
// Test de l'opérateur de division (/)
Fixed quotient = a / b;
std::cout << "Division: " << quotient << std::endl;
// Test de l'opérateur de comparaison (==)
bool isEqual = (a == b);
std::cout << "Is a equal to b? " << std::boolalpha << isEqual << std::endl;
// Test de l'opérateur de comparaison (!=)
bool isNotEqual = (a != b);
std::cout << "Is a not equal to b? " << std::boolalpha << isNotEqual << std::endl;
// Test de l'opérateur de comparaison (<)
bool isLessThan = (a < b);
std::cout << "Is a less than b? " << std::boolalpha << isLessThan << std::endl;
// Test de l'opérateur de comparaison (>)
bool isGreaterThan = (a > b);
std::cout << "Is a greater than b? " << std::boolalpha << isGreaterThan << std::endl;
// Test de l'opérateur de comparaison (<=)
bool isLessThanOrEqual = (a <= b);
std::cout << "Is a less than or equal to b? " << std::boolalpha << isLessThanOrEqual << std::endl;
// Test de l'opérateur de comparaison (>=)
bool isGreaterThanOrEqual = (a >= b);
std::cout << "Is a greater than or equal to b? " << std::boolalpha << isGreaterThanOrEqual << std::endl;
}
return 0;
} }