28const int Fixed::fractionalBits;
39Fixed::Fixed(
const int raw) : fixedPointValue(raw << fractionalBits) {
51Fixed::Fixed(
const float raw) : fixedPointValue(static_cast<int>(roundf(raw * (1 << fractionalBits)))) {
71 this->fixedPointValue = other.fixedPointValue;
81 return this->fixedPointValue;
92float Fixed::toFloat(
void)
const {
return static_cast<float>(this->fixedPointValue) / (1 << fractionalBits); }
101int Fixed::toInt(
void)
const {
return this->fixedPointValue >> fractionalBits; }
114 o <<
fixed.toFloat();
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
ios_base & fixed(ios_base &__base)
int toInt(void) const
Converts the fixed-point value to an integer value (truncates the fractional part).
int getRawBits(void) const
Gets the raw value of the fixed-point number.
void setRawBits(int const raw)
Sets the raw value of the fixed-point number.
Fixed & operator=(const Fixed &other)
Copy assignment operator.
Fixed()
Default constructor.
float toFloat(void) const
Converts the fixed-point value to a floating-point value.
std::ostream & operator<<(std::ostream &o, const Fixed &fixed)
Overloads the output stream operator to insert the float representation of the fixed-point number int...
Header file for the Fixed class representing fixed-point numbers with overloaded operators and min/ma...