FIXED_POINTS_BEGIN_NAMESPACE // // Constructors // template< unsigned Integer, unsigned Fraction > constexpr UFixed::UFixed(void) : Base() { } template< unsigned Integer, unsigned Fraction > constexpr UFixed::UFixed(const IntegerType & integer) : Base(RawType(static_cast(integer) << FractionSize)) { } template< unsigned Integer, unsigned Fraction > constexpr UFixed::UFixed(const IntegerType & integer, const FractionType & fraction) : Base(RawType((static_cast(integer) << FractionSize) | fraction)) { } // // Getters // template< unsigned Integer, unsigned Fraction > constexpr typename UFixed::InternalType UFixed::getInternal(void) const { return this->value; } template< unsigned Integer, unsigned Fraction > constexpr typename UFixed::IntegerType UFixed::getInteger(void) const { return static_cast(this->value >> IntegerShift) & IntegerMask; } template< unsigned Integer, unsigned Fraction > constexpr typename UFixed::FractionType UFixed::getFraction(void) const { return static_cast(this->value >> FractionShift) & FractionMask; } // // Cast Operators // template< unsigned Integer, unsigned Fraction > constexpr UFixed::operator IntegerType(void) const { return this->getInteger(); } template< unsigned Integer, unsigned Fraction > constexpr UFixed::operator float(void) const { return ((this->value & IdentityMask) * (1.0f / Scale)); } template< unsigned Integer, unsigned Fraction > constexpr UFixed::operator double(void) const { return ((this->value & IdentityMask) * (1.0 / Scale)); } template< unsigned Integer, unsigned Fraction > template< unsigned IntegerOut, unsigned FractionOut > constexpr UFixed::operator UFixed(void) const { using OutputType = UFixed; using OutputInternalType = typename OutputType::InternalType; using OutputShiftType = typename OutputType::ShiftType; using InputType = UFixed; using InputInternalType = typename InputType::InternalType; using InputShiftType = typename InputType::ShiftType; return (FractionOut > FractionSize) ? OutputType::fromInternal(static_cast(static_cast(this->value) << ((FractionOut > FractionSize) ? (FractionOut - FractionSize) : 0))) : (FractionSize > FractionOut) ? OutputType::fromInternal(static_cast(static_cast(this->value) >> ((FractionSize > FractionOut) ? (FractionSize - FractionOut) : 0))) : OutputType::fromInternal(this->value); } // // Static Functions // template< unsigned Integer, unsigned Fraction > constexpr UFixed UFixed::fromInternal(const typename UFixed::InternalType & value) { return UFixed(RawType(value)); } // // Member Operators // template< unsigned Integer, unsigned Fraction > UFixed & UFixed::operator ++(void) { this->value += (1 << FractionSize); return *this; } template< unsigned Integer, unsigned Fraction > UFixed & UFixed::operator --(void) { this->value -= (1 << FractionSize); return *this; } // // Compound Assignment Operators // template< unsigned Integer, unsigned Fraction > UFixed & UFixed::operator +=(const UFixed & other) { this->value += other.value; return *this; } template< unsigned Integer, unsigned Fraction > UFixed & UFixed::operator -=(const UFixed & other) { this->value -= other.value; return *this; } template< unsigned Integer, unsigned Fraction > UFixed & UFixed::operator *=(const UFixed & other) { using InternalType = typename UFixed::InternalType; using PrecisionType = typename UFixed::InternalType; const PrecisionType temp = (static_cast(this->value) * static_cast(other.value)) >> FractionSize; this->value = static_cast(temp); return *this; } template< unsigned Integer, unsigned Fraction > UFixed & UFixed::operator /=(const UFixed & other) { using InternalType = typename UFixed::InternalType; using PrecisionType = typename UFixed::InternalType; const PrecisionType temp = (static_cast(this->value) << FractionSize) / static_cast(other.value); this->value = static_cast(temp); return *this; } FIXED_POINTS_END_NAMESPACE