diff --git a/d02/ex02/Fixed.cpp b/d02/ex02/Fixed.cpp index d6a1a22..8de7902 100644 --- a/d02/ex02/Fixed.cpp +++ b/d02/ex02/Fixed.cpp @@ -94,24 +94,44 @@ Fixed & Fixed::operator=( Fixed const & rhs ) { } /* - * other operators + * 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(); +} +bool Fixed::operator> (Fixed const & rhs) const { return this->toFloat() > rhs.toFloat(); } -//Fixed operator> (Fixed const & rhs) const { +bool Fixed::operator<=(Fixed const & rhs) const { + return this->toFloat() <= rhs.toFloat(); +} +bool Fixed::operator>=(Fixed const & rhs) const { + return this->toFloat() >= rhs.toFloat(); +} +bool Fixed::operator==(Fixed const & rhs) const { + return this->toFloat() == rhs.toFloat(); +} +bool Fixed::operator!=(Fixed const & rhs) const { + return this->toFloat() != rhs.toFloat(); +} +Fixed Fixed::operator+ ( Fixed const & rhs ) const { + return Fixed( this->toFloat() + rhs.toFloat() ); +} +Fixed Fixed::operator- ( Fixed const & rhs ) const { + return Fixed( this->toFloat() - rhs.toFloat() ); +} +Fixed Fixed::operator* ( Fixed const & rhs ) const { + return Fixed( this->toFloat() * rhs.toFloat() ); +} +Fixed Fixed::operator/ ( Fixed const & rhs ) const { + return Fixed( this->toFloat() / rhs.toFloat() ); +} +//void Fixed::operator++( void ){ +// this->_value += 1; //} -//Fixed operator<=(Fixed const & rhs) const { -//} -//Fixed operator>=(Fixed const & rhs) const { -//} -//Fixed operator==(Fixed const & rhs) const { -//} -//Fixed operator!=(Fixed const & rhs) const { +//void Fixed::operator--( void ){ +// this->_value -= 1; //} diff --git a/d02/ex02/Fixed.hpp b/d02/ex02/Fixed.hpp index 066237b..62e199c 100644 --- a/d02/ex02/Fixed.hpp +++ b/d02/ex02/Fixed.hpp @@ -16,13 +16,18 @@ public: Fixed(float const floater); 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; + bool operator> (Fixed const & rhs) const; + bool operator<=(Fixed const & rhs) const; + bool operator>=(Fixed const & rhs) const; + bool 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; +// void operator++(void); +// void operator--(void); int getRawBits(void) const; void setRawBits(int const raw); diff --git a/d02/ex02/Makefile b/d02/ex02/Makefile index 0712445..5531831 100644 --- a/d02/ex02/Makefile +++ b/d02/ex02/Makefile @@ -4,7 +4,7 @@ # . value . or .cpp # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -NAME = fixed +NAME = operators CC = clang++ CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98 diff --git a/d02/ex02/fixed b/d02/ex02/fixed deleted file mode 100755 index 69fcc15..0000000 Binary files a/d02/ex02/fixed and /dev/null differ diff --git a/d02/ex02/main.cpp b/d02/ex02/main.cpp index fb6ddb0..2ef4f05 100644 --- a/d02/ex02/main.cpp +++ b/d02/ex02/main.cpp @@ -1,5 +1,6 @@ #include "Fixed.hpp" #include +#include int main( void ) { @@ -20,13 +21,73 @@ int main( void ) { Fixed d(5); Fixed e; - std::cout << "c: " << d << '\n'; - std::cout << "d: " << c << '\n'; - if (c < d) - e = c; - else - e = d; - std::cout << "e: " << e << '\n'; + std::cout << "c: " << c << '\n'; + std::cout << "d: " << d << "\n\n"; + + // ">" + std::cout << "e = greater of (c, d) : e == " << (e = (c > d) ? c : d) << '\n'; + std::cout << "e:" << e << " c:" << c << " d:" << d << '\n'; + std::cout << "e > c ? : " << (e > c) << '\n'; + std::cout << "e > d ? : " << (e > d) << "\n\n"; + // "<" + std::cout << "e = smaller of (c, d) : e == " << (e = (c < d) ? c : d) << '\n'; + std::cout << "e:" << e << " c:" << c << " d:" << d << '\n'; + std::cout << "e < c ? : " << (e < c) << '\n'; + std::cout << "e < d ? : " << (e < d) << "\n\n"; + // "<=" + std::cout << "e:" << e << " c:" << c << " d:" << d << '\n'; + std::cout << "e <= c ? : " << (e <= c) << '\n'; + std::cout << "e <= d ? : " << (e <= d) << "\n\n"; + // ">=" + std::cout << "e:" << e << " c:" << c << " d:" << d << '\n'; + std::cout << "e >= c ? : " << (e >= c) << '\n'; + std::cout << "e >= d ? : " << (e >= d) << "\n\n"; + // "==" + std::cout << "e:" << e << " c:" << c << " d:" << d << '\n'; + std::cout << "e == c ? : " << (e == c) << '\n'; + std::cout << "e == d ? : " << (e == d) << "\n\n"; + // "!=" + std::cout << "e:" << e << " c:" << c << " d:" << d << '\n'; + std::cout << "e != c ? : " << (e != c) << '\n'; + std::cout << "e != d ? : " << (e != d) << "\n\n"; + // "+" + std::cout << "e:" << e << " c:" << c << " d:" << d << '\n'; + std::cout << "e = c + d : " << (e = c + d) << "\n"; + std::cout << "e = e + c + d : " << (e = e + c + d) << "\n\n"; + // "-" + std::cout << "e:" << e << " c:" << c << " d:" << d << '\n'; + std::cout << "e = d - e ? : " << (e = d - e) << "\n"; + std::cout << "e = c - d - e ? : " << (e = c - d - e) << "\n\n"; + // "*" + std::cout << "e:" << e << " c:" << c << " d:" << d << '\n'; + std::cout << "e = d * c ? : " << (e = d * c) << "\n"; + std::cout << "e = d * c * c ? : " << (e = d * c * c) << "\n\n"; + // "/" + std::cout << "e:" << e << " c:" << c << " d:" << d << '\n'; + std::cout << "e = d / c ? : " << (e = d / c) << "\n"; + std::cout << "e = d / c / e ? : " << (e = d / c / e) << "\n\n"; + // "+ - * /" + Fixed f; + Fixed g; + std::cout << "f:" << f << " e:" << e << " c:" << c << " d:" << d << '\n'; + std::cout << "f = e + d / c - d / e * c ? : " << (f = e + d / c - d / e * c) << '\n'; + std::cout << "g = d / c ? : " << std::setw(5) << std::left << (g = d / c) << "[f:" << std::setw(5) << std::left << f << " g:" << std::setw(5) << std::left << g << " e:" << e << " c:" << c << " d:" << d << "]\n"; + std::cout << "g = e + g ? : " << std::setw(5) << std::left << (g = e + g) << "[f:" << std::setw(5) << std::left << f << " g:" << std::setw(5) << std::left << g << " e:" << e << " c:" << c << " d:" << d << "]\n"; + std::cout << "f = d / e ? : " << std::setw(5) << std::left << (f = d / e) << "[f:" << std::setw(5) << std::left << f << " g:" << std::setw(5) << std::left << g << " e:" << e << " c:" << c << " d:" << d << "]\n"; + std::cout << "f = f * c ? : " << std::setw(5) << std::left << (f = f * c) << "[f:" << std::setw(5) << std::left << f << " g:" << std::setw(5) << std::left << g << " e:" << e << " c:" << c << " d:" << d << "]\n"; + std::cout << "f = g - f ? : " << std::setw(5) << std::left << (f = g - f) << "[f:" << std::setw(5) << std::left << f << " g:" << std::setw(5) << std::left << g << " e:" << e << " c:" << c << " d:" << d << "]\n"; + // "++x" +// std::cout << "e : " << e << '\n'; +// std::cout << "e++ : " << ++e << "\n\n"; +// // "--x" +// std::cout << "e : " << e << '\n'; +// std::cout << "e-- : " << --e << "\n\n"; + // "x++" +// std::cout << "e : " << e << '\n'; +// std::cout << "e++ : " << e++ << "\n\n"; +// // "x--" +// std::cout << "e : " << e << '\n'; +// std::cout << "e-- : " << e-- << "\n\n"; return 0; } diff --git a/d02/ex02/operators b/d02/ex02/operators new file mode 100755 index 0000000..1311aab Binary files /dev/null and b/d02/ex02/operators differ