mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-29 01:10:35 +08:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user