Compare commits

..

5 Commits

Author SHA1 Message Date
ffc3d04ca3 remove executable 2023-08-08 19:24:54 +02:00
18a2008a96 clean: 2023-08-07 19:06:43 +02:00
13f208d577 invert print 2023-08-07 16:59:31 +02:00
fe32ade285 remove com 2023-08-07 16:57:03 +02:00
1c500e28bf int and float constructor right print 2023-08-07 16:44:03 +02:00
6 changed files with 13 additions and 28 deletions

View File

@ -1,3 +1,5 @@
#pragma once
class Fixed class Fixed
{ {
private: private:

View File

@ -22,13 +22,13 @@ Fixed::Fixed(const Fixed& src)
Fixed::Fixed(const int& src) Fixed::Fixed(const int& src)
{ {
std::cout << "Copy constructor called" << std::endl; std::cout << "Int constructor called" << std::endl;
this->_value = src << this->_nb_bits; this->_value = src << this->_nb_bits;
} }
Fixed::Fixed(const float& src) Fixed::Fixed(const float& src)
{ {
std::cout << "Copy constructor called" << std::endl; std::cout << "Float constructor called" << std::endl;
this->_value = (int) roundf(src * (1 << this->_nb_bits)); this->_value = (int) roundf(src * (1 << this->_nb_bits));
} }

View File

@ -1,7 +1,6 @@
#ifndef FIXED_H #pragma once
# define FIXED_H
# include <ostream> #include <ostream>
class Fixed class Fixed
{ {
@ -25,5 +24,3 @@ class Fixed
}; };
std::ostream& operator << (std::ostream &out, const Fixed& fixed); std::ostream& operator << (std::ostream &out, const Fixed& fixed);
#endif

View File

@ -22,13 +22,13 @@ Fixed::Fixed(const Fixed& src)
Fixed::Fixed(const int& src) Fixed::Fixed(const int& src)
{ {
std::cout << "Copy constructor called" << std::endl; std::cout << "Int constructor called" << std::endl;
this->_value = src << this->_nb_bits; this->_value = src << this->_nb_bits;
} }
Fixed::Fixed(const float& src) Fixed::Fixed(const float& src)
{ {
std::cout << "Copy constructor called" << std::endl; std::cout << "Float constructor called" << std::endl;
this->_value = (int) roundf(src * (1 << this->_nb_bits)); this->_value = (int) roundf(src * (1 << this->_nb_bits));
} }

View File

@ -1,5 +1,4 @@
#ifndef FIXED_H #pragma once
# define FIXED_H
# include <ostream> # include <ostream>
@ -47,5 +46,3 @@ class Fixed
}; };
std::ostream& operator << (std::ostream &out, const Fixed& fixed); std::ostream& operator << (std::ostream &out, const Fixed& fixed);
#endif

View File

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