From cc7c346f84a62ee4e4b084bf675d824452c4116a Mon Sep 17 00:00:00 2001 From: Madeline Busig Date: Fri, 2 Aug 2024 23:27:13 -0600 Subject: [PATCH] Add fixed point assignment operators --- include/mtl/fixed.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/mtl/fixed.hpp b/include/mtl/fixed.hpp index 83b08ee..02b84e3 100644 --- a/include/mtl/fixed.hpp +++ b/include/mtl/fixed.hpp @@ -105,12 +105,20 @@ public: constexpr fixed operator+(fixed rhs) const { return from_raw(x + rhs.x); } + constexpr fixed& operator+=(fixed rhs) { + x += rhs.x; + return *this; + } /** * \brief Fixed point subtraction */ constexpr fixed operator-(fixed rhs) const { return from_raw(x - rhs.x); } + constexpr fixed& operator-=(fixed rhs) { + x -= rhs.x; + return *this; + } constexpr fixed operator-() const { return from_raw(-x); } @@ -135,6 +143,10 @@ public: return from_raw(raw_result); } + fixed& operator*=(fixed rhs) { + *this = *this * rhs; + return *this; + } /** * \brief Fixed point division @@ -152,6 +164,10 @@ public: * Placed in IWRAM */ fixed operator/(fixed rhs) const; + fixed& operator/=(fixed rhs) { + *this = *this / rhs; + return *this; + } }; } // namespace mtl