30const int Fixed::fractionalBits;
35Fixed::Fixed(
const int raw) : fixedPointValue(raw << fractionalBits) {}
38Fixed::Fixed(
const float raw) : fixedPointValue(static_cast<int>(roundf(raw * (1 << fractionalBits)))) {}
47 this->fixedPointValue = other.fixedPointValue;
60float Fixed::toFloat(
void)
const {
return static_cast<float>(this->fixedPointValue) / (1 << fractionalBits); }
62int Fixed::toInt(
void)
const {
return this->fixedPointValue >> fractionalBits; }
142 if (other.fixedPointValue == 0) {
156 this->fixedPointValue += (1 << fractionalBits);
167 this->fixedPointValue += (1 << fractionalBits);
176 this->fixedPointValue -= (1 << fractionalBits);
187 this->fixedPointValue -= (1 << fractionalBits);
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).
bool operator>=(const Fixed &other) const
Overloads the greater-than-or-equal-to operator.
int getRawBits(void) const
Gets the raw value of the fixed-point number.
bool operator<(const Fixed &other) const
Overloads the less-than operator.
void setRawBits(int const raw)
Sets the raw value of the fixed-point number.
Fixed & operator--()
Overloads the pre-decrement operator.
static Fixed & max(Fixed &a, Fixed &b)
Static member function to find the maximum of two Fixed objects (non-const).
Fixed operator/(const Fixed &other) const
Overloads the division operator.
bool operator<=(const Fixed &other) const
Overloads the less-than-or-equal-to operator.
bool operator>(const Fixed &other) const
Overloads the greater-than operator.
bool operator==(const Fixed &other) const
Overloads the equality operator.
Fixed & operator=(const Fixed &other)
Copy assignment operator.
Fixed operator-(const Fixed &other) const
Overloads the subtraction operator.
Fixed operator*(const Fixed &other) const
Overloads the multiplication operator.
Fixed()
Default constructor.
Fixed & operator++()
Overloads the pre-increment operator.
static Fixed & min(Fixed &a, Fixed &b)
Static member function to find the minimum of two Fixed objects (non-const).
Fixed operator+(const Fixed &other) const
Overloads the addition operator.
float toFloat(void) const
Converts the fixed-point value to a floating-point value.
bool operator!=(const Fixed &other) const
Overloads the inequality operator.
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...