From ecc2ca7f9829cc0ca70fae7583877d8a62c06d3e Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Mon, 13 Dec 2021 13:29:38 -0500 Subject: [PATCH] mathlib: int16_t negate explicitly handle both INT16_MIN and INT16_MAX - technically negating INT16_MAX doesn't need special handling, but this ensures any simple saturation logic downstream works by default --- src/lib/mathlib/math/Functions.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/mathlib/math/Functions.hpp b/src/lib/mathlib/math/Functions.hpp index 486ea52b6e..f3e715f0e8 100644 --- a/src/lib/mathlib/math/Functions.hpp +++ b/src/lib/mathlib/math/Functions.hpp @@ -227,7 +227,14 @@ constexpr T negate(T value) template<> constexpr int16_t negate(int16_t value) { - return (value == INT16_MIN) ? INT16_MAX : -value; + if (value == INT16_MAX) { + return INT16_MIN; + + } else if (value == INT16_MIN) { + return INT16_MAX; + } + + return -value; } inline bool isFinite(const float &value)