overload operators en cours
This commit is contained in:
@@ -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 {
|
bool Fixed::operator< (Fixed const & rhs) const {
|
||||||
|
return this->toFloat() < rhs.toFloat();
|
||||||
|
}
|
||||||
|
bool Fixed::operator> (Fixed const & rhs) const {
|
||||||
return this->toFloat() > rhs.toFloat();
|
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 {
|
//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 {
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,13 +16,18 @@ public:
|
|||||||
Fixed(float const floater);
|
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;
|
bool operator< (Fixed const & rhs) const;
|
||||||
// Fixed operator> (Fixed const & rhs) const;
|
bool operator> (Fixed const & rhs) const;
|
||||||
// Fixed operator<=(Fixed const & rhs) const;
|
bool operator<=(Fixed const & rhs) const;
|
||||||
// Fixed operator>=(Fixed const & rhs) const;
|
bool operator>=(Fixed const & rhs) const;
|
||||||
// Fixed operator==(Fixed const & rhs) const;
|
bool operator==(Fixed const & rhs) const;
|
||||||
// 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;
|
||||||
|
// void operator++(void);
|
||||||
|
// void operator--(void);
|
||||||
|
|
||||||
int getRawBits(void) const;
|
int getRawBits(void) const;
|
||||||
void setRawBits(int const raw);
|
void setRawBits(int const raw);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
# . value . or .cpp #
|
# . value . or .cpp #
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||||
|
|
||||||
NAME = fixed
|
NAME = operators
|
||||||
|
|
||||||
CC = clang++
|
CC = clang++
|
||||||
CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98
|
CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98
|
||||||
|
|||||||
BIN
d02/ex02/fixed
BIN
d02/ex02/fixed
Binary file not shown.
@@ -1,5 +1,6 @@
|
|||||||
#include "Fixed.hpp"
|
#include "Fixed.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
int main( void ) {
|
int main( void ) {
|
||||||
|
|
||||||
@@ -20,13 +21,73 @@ int main( void ) {
|
|||||||
Fixed d(5);
|
Fixed d(5);
|
||||||
Fixed e;
|
Fixed e;
|
||||||
|
|
||||||
std::cout << "c: " << d << '\n';
|
std::cout << "c: " << c << '\n';
|
||||||
std::cout << "d: " << c << '\n';
|
std::cout << "d: " << d << "\n\n";
|
||||||
if (c < d)
|
|
||||||
e = c;
|
// ">"
|
||||||
else
|
std::cout << "e = greater of (c, d) : e == " << (e = (c > d) ? c : d) << '\n';
|
||||||
e = d;
|
std::cout << "e:" << e << " c:" << c << " d:" << d << '\n';
|
||||||
std::cout << "e: " << e << '\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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
d02/ex02/operators
Executable file
BIN
d02/ex02/operators
Executable file
Binary file not shown.
Reference in New Issue
Block a user