#include "Fixed.hpp" #include #include #include Fixed::~Fixed() { std::cout << "Destructor called" << std::endl; } Fixed::Fixed() { this->_value = 0; std::cout << "Default constructor called" << std::endl; } Fixed::Fixed(const Fixed& src) { std::cout << "Copy constructor called" << std::endl; this->_value = src.getRawBits(); } Fixed::Fixed(const int& src) { std::cout << "Copy constructor called" << std::endl; this->_value = src << this->_nb_bits; } Fixed::Fixed(const float& src) { std::cout << "Copy constructor called" << std::endl; this->_value = (int) roundf(src * (1 << this->_nb_bits)); } Fixed& Fixed::operator=(const Fixed& src) { std::cout << "Copy assignment operator called" << std::endl; this->_value = src.getRawBits(); return (*this); } int Fixed::getRawBits() const { std::cout << "getRawBits member function called" << std::endl; return (this->_value); } void Fixed::setRawBits(const int raw) { std::cout << "setRawBits member function called" << std::endl; this->_value = raw; } float Fixed::toFloat(void) const { return ((float) this->_value / (1 << this->_nb_bits)); } int Fixed::toInt() const { return ((int) (roundf(this->toFloat()))); } std::ostream& operator<<(std::ostream &out, const Fixed& fixed) { out << (fixed.toFloat()); return (out); }