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
This commit is contained in:
Daniel Agar 2021-12-13 13:29:38 -05:00
parent d59d16a6cd
commit ecc2ca7f98

View File

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