Add support for post increment and decrement

pull/69/head
Dirk Petrautzki 4 years ago
parent 8d0ef25aec
commit 0be7375662
  1. 2
      src/FixedPoints/SFixed.h
  2. 16
      src/FixedPoints/SFixedMemberFunctions.h
  3. 2
      src/FixedPoints/UFixed.h
  4. 20
      src/FixedPoints/UFixedMemberFunctions.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);

@ -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
//

@ -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);

@ -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
//

Loading…
Cancel
Save