feat: finishing the ex02

This commit is contained in:
Raphael 2025-01-09 14:52:39 +01:00
parent 95fb804997
commit 1179527d22
7 changed files with 373 additions and 13 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/21 19:52:44 by rparodi #+# #+# */
/* Updated: 2024/12/27 13:06:30 by rparodi ### ########.fr */
/* Updated: 2024/12/27 13:42:55 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,13 +29,11 @@ Fixed::Fixed(const Fixed &copy) {
}
Fixed::Fixed(const int &integer) {
this->_integer_value = integer;
this->_floating_value = integer;
this->_fixed_value = integer << _fractionnal;
}
Fixed::Fixed(const float &floating) {
this->_integer_value = roundf(floating);
this->_floating_value = floating;
this->_fixed_value = (int)(roundf(floating * (1 << this->_fractionnal)));
}
Fixed::~Fixed() {
@ -62,14 +60,14 @@ void Fixed::setRawBits(const int value) {
}
int Fixed::toInt() const {
return (std::roundf(this->_floating_value));
return ((int)this->_fixed_value >> this->_fractionnal);
}
float Fixed::toFloat() const {
return (this->_floating_value);
return ((float)this->_fixed_value / ( 1 << this->_fractionnal));
}
int Fixed::getRawBits() {
int Fixed::getRawBits() const {
std::cout << "getRawBits member function called" << std::endl;
return this->_fixed_value;
}