From 55edb9f634573906ee0f6abc70f9630c5c1009a4 Mon Sep 17 00:00:00 2001 From: Myles 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