Skip to content

Commit

Permalink
mathlib: int16_t negate explicitly handle both INT16_MIN and INT16_MAX
Browse files Browse the repository at this point in the history
 - technically negating INT16_MAX doesn't need special handling, but
this ensures any simple saturation logic downstream works by default
  • Loading branch information
dagar committed Dec 15, 2021
1 parent d59d16a commit ecc2ca7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib/mathlib/math/Functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,14 @@ constexpr T negate(T value)
template<>
constexpr int16_t negate<int16_t>(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)
Expand Down

0 comments on commit ecc2ca7

Please sign in to comment.