d02 ex02 et ex01 variables statics et min max

This commit is contained in:
Hugo LAMY
2022-02-18 18:17:00 +01:00
parent 494cb84f13
commit bd83d90b5f
9 changed files with 41 additions and 280 deletions

View File

@@ -12,8 +12,8 @@
*/
int const Fixed::_frac = 8;
int const Fixed::_fmax = -1U >> (_frac +1);
int const Fixed::_fmin = ~_fmax;
int const Fixed::_max = -1U >> (_frac +1);
int const Fixed::_min = ~_max;
/*
* default constructor / copy constructor / destructor
@@ -42,19 +42,19 @@ Fixed::~Fixed( void ) {
Fixed::Fixed(int integer) {
std::cout << "Int constructor called" << '\n';
if (integer < this->_fmin || integer > this->_fmax)
if (integer < Fixed::_min || integer > Fixed::_max)
std::cout << "error: integer out of range" << '\n';
else
this->_value = integer << this->_frac;
this->_value = integer << Fixed::_frac;
}
Fixed::Fixed(float const floater) {
std::cout << "Float constructor called" << '\n';
if (floater < this->_fmin || floater > this->_fmax)
if (floater < Fixed::_min || floater > Fixed::_max)
std::cout << "error: float out of range" << '\n';
else
this->_value = roundf(floater * (1 << this->_frac));
this->_value = roundf(floater * (1 << Fixed::_frac));
}
/*
@@ -81,10 +81,10 @@ void Fixed::setRawBits( int const raw ) {
}
int Fixed::toInt( void ) const {
return (this->_value >> this->_frac);
return (this->_value >> Fixed::_frac);
}
float Fixed::toFloat( void ) const {
return ((float)this->_value / (float)(1 << this->_frac));
return ((float)this->_value / (float)(1 << Fixed::_frac));
}
/*

View File

@@ -26,8 +26,8 @@ private:
int _value;
static int const _frac;
static int const _fmax;
static int const _fmin;
static int const _max;
static int const _min;
};

BIN
d02/ex01/fixed Executable file

Binary file not shown.