d02 ex02 et ex01 variables statics et min max
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user