diff --git a/d02/ex01/Fixed.cpp b/d02/ex01/Fixed.cpp index 163a98b..0b1d00b 100644 --- a/d02/ex01/Fixed.cpp +++ b/d02/ex01/Fixed.cpp @@ -125,8 +125,8 @@ float Fixed::toFloat( void ) const { * took here : https://github.com/pgomez-a/42_CPP_Piscine/blob/master/cpp02/ex01/Fixed.cpp */ -std::ostream & operator<<(std::ostream & out, Fixed const & fixed) +std::ostream & operator<<(std::ostream & o, Fixed const & rhs) { - out << fixed.toFloat(); - return (out); + o << rhs.toFloat(); + return (o); } diff --git a/d02/ex01/Fixed.hpp b/d02/ex01/Fixed.hpp index 42619aa..84f09bd 100644 --- a/d02/ex01/Fixed.hpp +++ b/d02/ex01/Fixed.hpp @@ -30,6 +30,6 @@ private: }; -std::ostream & operator<<(std::ostream & out, Fixed const & fixed); +std::ostream & operator<<(std::ostream & o, Fixed const & rhs); #endif diff --git a/d02/ex02/Fixed.cpp b/d02/ex02/Fixed.cpp index 163a98b..d6a1a22 100644 --- a/d02/ex02/Fixed.cpp +++ b/d02/ex02/Fixed.cpp @@ -53,18 +53,15 @@ int const Fixed::_max = -1U >> (_frac +1); */ Fixed::Fixed() : _value(0) { - std::cout << "Default constructor called" << '\n'; return; } Fixed::Fixed(Fixed const & src) { - std::cout << "Copy constructor called" << '\n'; *this = src; return; } Fixed::~Fixed( void ) { - std::cout << "Destructor called" << '\n'; return; } @@ -73,8 +70,6 @@ Fixed::~Fixed( void ) { */ Fixed::Fixed(int integer) { - std::cout << "Int constructor called" << '\n'; - if (integer < ~this->_max || integer > this->_max) std::cout << "error: integer out of range" << '\n'; else @@ -82,8 +77,6 @@ Fixed::Fixed(int integer) { } Fixed::Fixed(float const floater) { - std::cout << "Float constructor called" << '\n'; - if (floater < ~this->_max || floater > this->_max) std::cout << "error: float out of range" << '\n'; else @@ -95,12 +88,33 @@ Fixed::Fixed(float const floater) { */ Fixed & Fixed::operator=( Fixed const & rhs ) { - std::cout << "Copy assignment operator called" << '\n'; if ( this != &rhs ) this->_value = rhs.getRawBits(); return *this; } +/* + * other operators + */ + +//Fixed Fixed::operator+( Fixed const & rhs ) const { +// return Fixed( this->toFloat() + rhs.toFloat() ); +//} +bool Fixed::operator< (Fixed const & rhs) const { + return this->toFloat() > rhs.toFloat(); +} +//Fixed operator> (Fixed const & rhs) const { +//} +//Fixed operator<=(Fixed const & rhs) const { +//} +//Fixed operator>=(Fixed const & rhs) const { +//} +//Fixed operator==(Fixed const & rhs) const { +//} +//Fixed operator!=(Fixed const & rhs) const { +//} + + /* * functions that returns _value */ @@ -125,8 +139,8 @@ float Fixed::toFloat( void ) const { * took here : https://github.com/pgomez-a/42_CPP_Piscine/blob/master/cpp02/ex01/Fixed.cpp */ -std::ostream & operator<<(std::ostream & out, Fixed const & fixed) +std::ostream & operator<<(std::ostream & o, Fixed const & rhs) { - out << fixed.toFloat(); - return (out); + o << rhs.toFloat(); + return (o); } diff --git a/d02/ex02/Fixed.hpp b/d02/ex02/Fixed.hpp index 42619aa..066237b 100644 --- a/d02/ex02/Fixed.hpp +++ b/d02/ex02/Fixed.hpp @@ -15,7 +15,14 @@ public: Fixed(int integer); Fixed(float const floater); - Fixed & operator=(Fixed const & rhs); // assignement operator + Fixed & operator= (Fixed const & rhs); // assignement operator +// Fixed operator+ (Fixed const & rhs) const; + bool operator< (Fixed const & rhs) const; +// Fixed operator> (Fixed const & rhs) const; +// Fixed operator<=(Fixed const & rhs) const; +// Fixed operator>=(Fixed const & rhs) const; +// Fixed operator==(Fixed const & rhs) const; +// Fixed operator!=(Fixed const & rhs) const; int getRawBits(void) const; void setRawBits(int const raw); @@ -30,6 +37,6 @@ private: }; -std::ostream & operator<<(std::ostream & out, Fixed const & fixed); +std::ostream & operator<<(std::ostream & o, Fixed const & rhs); #endif diff --git a/d02/ex02/fixed b/d02/ex02/fixed new file mode 100755 index 0000000..2dddd21 Binary files /dev/null and b/d02/ex02/fixed differ diff --git a/d02/ex02/main.cpp b/d02/ex02/main.cpp index 13402e6..26ecbfe 100644 --- a/d02/ex02/main.cpp +++ b/d02/ex02/main.cpp @@ -3,22 +3,30 @@ int main( void ) { - Fixed a; - Fixed const b( 10 ); - Fixed const c( 42.42f ); - Fixed const d( b ); + Fixed a(10); + Fixed b(5); + Fixed c; - a = Fixed( 1234.4321f ); + std::cout << "a: " << a << '\n'; + std::cout << "b: " << b << '\n'; + if (a < b) + c = a; + else + c = b; + std::cout << "c: " << c << '\n'; - std::cout << "a is " << a << std::endl; - std::cout << "b is " << b << std::endl; - std::cout << "c is " << c << std::endl; - std::cout << "d is " << d << std::endl; - - std::cout << "a is " << a.toInt() << " as integer" << std::endl; - std::cout << "b is " << b.toInt() << " as integer" << std::endl; - std::cout << "c is " << c.toInt() << " as integer" << std::endl; - std::cout << "d is " << d.toInt() << " as integer" << std::endl; +// Fixed a; +// 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 << b << std::endl; +// +// std::cout << Fixed::max( a, b ) << std::endl return 0; }