Add long double conversion operator (#34)

pull/39/head
Pharap 7 years ago committed by GitHub
parent fc3de879b1
commit d0c20218ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/FixedPoints/SFixed.h
  2. 11
      src/FixedPoints/SFixedMemberFunctions.h
  3. 1
      src/FixedPoints/UFixed.h
  4. 8
      src/FixedPoints/UFixedMemberFunctions.h

@ -74,6 +74,7 @@ public:
constexpr explicit operator IntegerType(void) const;
constexpr explicit operator float(void) const;
constexpr explicit operator double(void) const;
constexpr explicit operator long double(void) const;
template< unsigned IntegerOut, unsigned FractionOut >
constexpr explicit operator SFixed<IntegerOut, FractionOut>(void) const;

@ -71,7 +71,7 @@ constexpr SFixed<Integer, Fraction>::operator IntegerType(void) const
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::operator float(void) const
{
return (1.0f / Scale) *
return (1.0F / Scale) *
static_cast<InternalType>
((this->value & IdentityMask) |
((this->value < 0) ? ~IdentityMask : 0));
@ -86,6 +86,15 @@ constexpr SFixed<Integer, Fraction>::operator double(void) const
((this->value < 0) ? ~IdentityMask : 0));
}
template< unsigned Integer, unsigned Fraction >
constexpr SFixed<Integer, Fraction>::operator long double(void) const
{
return (1.0L / Scale) *
static_cast<InternalType>
((this->value & IdentityMask) |
((this->value < 0) ? ~IdentityMask : 0));
}
template< unsigned Integer, unsigned Fraction >
template< unsigned IntegerOut, unsigned FractionOut >
constexpr SFixed<Integer, Fraction>::operator SFixed<IntegerOut, FractionOut>(void) const

@ -74,6 +74,7 @@ public:
constexpr explicit operator IntegerType(void) const;
constexpr explicit operator float(void) const;
constexpr explicit operator double(void) const;
constexpr explicit operator long double(void) const;
template< unsigned IntegerOut, unsigned FractionOut >
constexpr explicit operator UFixed<IntegerOut, FractionOut>(void) const;

@ -71,7 +71,7 @@ constexpr UFixed<Integer, Fraction>::operator IntegerType(void) const
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::operator float(void) const
{
return ((this->value & IdentityMask) * (1.0f / Scale));
return ((this->value & IdentityMask) * (1.0F / Scale));
}
template< unsigned Integer, unsigned Fraction >
@ -80,6 +80,12 @@ constexpr UFixed<Integer, Fraction>::operator double(void) const
return ((this->value & IdentityMask) * (1.0 / Scale));
}
template< unsigned Integer, unsigned Fraction >
constexpr UFixed<Integer, Fraction>::operator long double(void) const
{
return ((this->value & IdentityMask) * (1.0L / Scale));
}
template< unsigned Integer, unsigned Fraction >
template< unsigned IntegerOut, unsigned FractionOut >
constexpr UFixed<Integer, Fraction>::operator UFixed<IntegerOut, FractionOut>(void) const

Loading…
Cancel
Save