From 0be73756626b4ad98f3dbed955ad3bdb016384b3 Mon Sep 17 00:00:00 2001 From: Dirk Petrautzki <dirk@dirk-petrautzki.de> Date: Fri, 4 Sep 2020 09:58:13 +0200 Subject: [PATCH] Add support for post increment and decrement --- src/FixedPoints/SFixed.h | 2 ++ src/FixedPoints/SFixedMemberFunctions.h | 16 ++++++++++++++++ src/FixedPoints/UFixed.h | 2 ++ src/FixedPoints/UFixedMemberFunctions.h | 20 ++++++++++++++++++-- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/FixedPoints/SFixed.h b/src/FixedPoints/SFixed.h index b2aa96d..ab31d01 100644 --- a/src/FixedPoints/SFixed.h +++ b/src/FixedPoints/SFixed.h @@ -108,6 +108,8 @@ public: constexpr SFixed operator -() const; SFixed & operator ++(); SFixed & operator --(); + SFixed operator ++(int); + SFixed operator --(int); SFixed & operator +=(const SFixed & other); SFixed & operator -=(const SFixed & other); SFixed & operator *=(const SFixed & other); diff --git a/src/FixedPoints/SFixedMemberFunctions.h b/src/FixedPoints/SFixedMemberFunctions.h index e2ab090..ee994e0 100644 --- a/src/FixedPoints/SFixedMemberFunctions.h +++ b/src/FixedPoints/SFixedMemberFunctions.h @@ -232,6 +232,22 @@ SFixed<Integer, Fraction> & SFixed<Integer, Fraction>::operator --() return *this; } +template< unsigned Integer, unsigned Fraction > +SFixed<Integer, Fraction> SFixed<Integer, Fraction>::operator ++(int) +{ + const SFixed<Integer, Fraction> old(*this); + ++(*this); + return old; +} + +template< unsigned Integer, unsigned Fraction > +SFixed<Integer, Fraction> SFixed<Integer, Fraction>::operator --(int) +{ + const SFixed<Integer, Fraction> old(*this); + --(*this); + return old; +} + // // Compound Assignment Operators // diff --git a/src/FixedPoints/UFixed.h b/src/FixedPoints/UFixed.h index 64079da..8facf28 100644 --- a/src/FixedPoints/UFixed.h +++ b/src/FixedPoints/UFixed.h @@ -108,6 +108,8 @@ public: UFixed & operator ++(); UFixed & operator --(); + UFixed operator ++(int); + UFixed operator --(int); UFixed & operator +=(const UFixed & other); UFixed & operator -=(const UFixed & other); UFixed & operator *=(const UFixed & other); diff --git a/src/FixedPoints/UFixedMemberFunctions.h b/src/FixedPoints/UFixedMemberFunctions.h index 9f7ddd0..7cf84e7 100644 --- a/src/FixedPoints/UFixedMemberFunctions.h +++ b/src/FixedPoints/UFixedMemberFunctions.h @@ -177,10 +177,10 @@ constexpr UFixed<Integer, Fraction>::operator UFixed<IntegerOut, FractionOut>() using OutputType = UFixed<IntegerOut, FractionOut>; using OutputInternalType = typename OutputType::InternalType; using OutputShiftType = typename OutputType::ShiftType; - + using InputType = UFixed<Integer, Fraction>; using InputShiftType = typename InputType::ShiftType; - + return (FractionOut > FractionSize) ? OutputType::fromInternal(static_cast<OutputInternalType>(static_cast<OutputShiftType>(this->value) << ((FractionOut > FractionSize) ? (FractionOut - FractionSize) : 0))) : @@ -217,6 +217,22 @@ UFixed<Integer, Fraction> & UFixed<Integer, Fraction>::operator --() return *this; } +template< unsigned Integer, unsigned Fraction > +UFixed<Integer, Fraction> UFixed<Integer, Fraction>::operator ++(int) +{ + const UFixed<Integer, Fraction> old(*this); + ++(*this); + return old; +} + +template< unsigned Integer, unsigned Fraction > +UFixed<Integer, Fraction> UFixed<Integer, Fraction>::operator --(int) +{ + const UFixed<Integer, Fraction> old(*this); + --(*this); + return old; +} + // // Compound Assignment Operators //