Skip to content

Commit d0c2021

Browse files
authored
Add long double conversion operator (#34)
1 parent fc3de87 commit d0c2021

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/FixedPoints/SFixed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class SFixed : FIXED_POINTS_DETAILS::SFixedBase< Integer, Fraction >
7474
constexpr explicit operator IntegerType(void) const;
7575
constexpr explicit operator float(void) const;
7676
constexpr explicit operator double(void) const;
77+
constexpr explicit operator long double(void) const;
7778

7879
template< unsigned IntegerOut, unsigned FractionOut >
7980
constexpr explicit operator SFixed<IntegerOut, FractionOut>(void) const;

src/FixedPoints/SFixedMemberFunctions.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ constexpr SFixed<Integer, Fraction>::operator IntegerType(void) const
7171
template< unsigned Integer, unsigned Fraction >
7272
constexpr SFixed<Integer, Fraction>::operator float(void) const
7373
{
74-
return (1.0f / Scale) *
74+
return (1.0F / Scale) *
7575
static_cast<InternalType>
7676
((this->value & IdentityMask) |
7777
((this->value < 0) ? ~IdentityMask : 0));
@@ -86,6 +86,15 @@ constexpr SFixed<Integer, Fraction>::operator double(void) const
8686
((this->value < 0) ? ~IdentityMask : 0));
8787
}
8888

89+
template< unsigned Integer, unsigned Fraction >
90+
constexpr SFixed<Integer, Fraction>::operator long double(void) const
91+
{
92+
return (1.0L / Scale) *
93+
static_cast<InternalType>
94+
((this->value & IdentityMask) |
95+
((this->value < 0) ? ~IdentityMask : 0));
96+
}
97+
8998
template< unsigned Integer, unsigned Fraction >
9099
template< unsigned IntegerOut, unsigned FractionOut >
91100
constexpr SFixed<Integer, Fraction>::operator SFixed<IntegerOut, FractionOut>(void) const

src/FixedPoints/UFixed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class UFixed : FIXED_POINTS_DETAILS::UFixedBase< Integer, Fraction >
7474
constexpr explicit operator IntegerType(void) const;
7575
constexpr explicit operator float(void) const;
7676
constexpr explicit operator double(void) const;
77+
constexpr explicit operator long double(void) const;
7778

7879
template< unsigned IntegerOut, unsigned FractionOut >
7980
constexpr explicit operator UFixed<IntegerOut, FractionOut>(void) const;

src/FixedPoints/UFixedMemberFunctions.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ constexpr UFixed<Integer, Fraction>::operator IntegerType(void) const
7171
template< unsigned Integer, unsigned Fraction >
7272
constexpr UFixed<Integer, Fraction>::operator float(void) const
7373
{
74-
return ((this->value & IdentityMask) * (1.0f / Scale));
74+
return ((this->value & IdentityMask) * (1.0F / Scale));
7575
}
7676

7777
template< unsigned Integer, unsigned Fraction >
@@ -80,6 +80,12 @@ constexpr UFixed<Integer, Fraction>::operator double(void) const
8080
return ((this->value & IdentityMask) * (1.0 / Scale));
8181
}
8282

83+
template< unsigned Integer, unsigned Fraction >
84+
constexpr UFixed<Integer, Fraction>::operator long double(void) const
85+
{
86+
return ((this->value & IdentityMask) * (1.0L / Scale));
87+
}
88+
8389
template< unsigned Integer, unsigned Fraction >
8490
template< unsigned IntegerOut, unsigned FractionOut >
8591
constexpr UFixed<Integer, Fraction>::operator UFixed<IntegerOut, FractionOut>(void) const

0 commit comments

Comments
 (0)