From d0c20218ca54404aad4ccbad1e7a1e54fef7c963 Mon Sep 17 00:00:00 2001 From: Pharap <2933055+Pharap@users.noreply.github.com> Date: Wed, 4 Apr 2018 08:18:26 +0100 Subject: [PATCH] Add long double conversion operator (#34) --- src/FixedPoints/SFixed.h | 1 + src/FixedPoints/SFixedMemberFunctions.h | 11 ++++++++++- src/FixedPoints/UFixed.h | 1 + src/FixedPoints/UFixedMemberFunctions.h | 8 +++++++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/FixedPoints/SFixed.h b/src/FixedPoints/SFixed.h index 04ad53b..9576cbe 100644 --- a/src/FixedPoints/SFixed.h +++ b/src/FixedPoints/SFixed.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(void) const; diff --git a/src/FixedPoints/SFixedMemberFunctions.h b/src/FixedPoints/SFixedMemberFunctions.h index aa8b3b9..82848f4 100644 --- a/src/FixedPoints/SFixedMemberFunctions.h +++ b/src/FixedPoints/SFixedMemberFunctions.h @@ -71,7 +71,7 @@ constexpr SFixed::operator IntegerType(void) const template< unsigned Integer, unsigned Fraction > constexpr SFixed::operator float(void) const { - return (1.0f / Scale) * + return (1.0F / Scale) * static_cast ((this->value & IdentityMask) | ((this->value < 0) ? ~IdentityMask : 0)); @@ -86,6 +86,15 @@ constexpr SFixed::operator double(void) const ((this->value < 0) ? ~IdentityMask : 0)); } +template< unsigned Integer, unsigned Fraction > +constexpr SFixed::operator long double(void) const +{ + return (1.0L / Scale) * + static_cast + ((this->value & IdentityMask) | + ((this->value < 0) ? ~IdentityMask : 0)); +} + template< unsigned Integer, unsigned Fraction > template< unsigned IntegerOut, unsigned FractionOut > constexpr SFixed::operator SFixed(void) const diff --git a/src/FixedPoints/UFixed.h b/src/FixedPoints/UFixed.h index 3becdf5..600eee5 100644 --- a/src/FixedPoints/UFixed.h +++ b/src/FixedPoints/UFixed.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 UFixed(void) const; diff --git a/src/FixedPoints/UFixedMemberFunctions.h b/src/FixedPoints/UFixedMemberFunctions.h index 55429cd..0b6faae 100644 --- a/src/FixedPoints/UFixedMemberFunctions.h +++ b/src/FixedPoints/UFixedMemberFunctions.h @@ -71,7 +71,7 @@ constexpr UFixed::operator IntegerType(void) const template< unsigned Integer, unsigned Fraction > constexpr UFixed::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::operator double(void) const return ((this->value & IdentityMask) * (1.0 / Scale)); } +template< unsigned Integer, unsigned Fraction > +constexpr UFixed::operator long double(void) const +{ + return ((this->value & IdentityMask) * (1.0L / Scale)); +} + template< unsigned Integer, unsigned Fraction > template< unsigned IntegerOut, unsigned FractionOut > constexpr UFixed::operator UFixed(void) const