mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-24 06:03:33 +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<>
|
template<>
|
||||||
constexpr int16_t negate<int16_t>(int16_t value)
|
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)
|
inline bool isFinite(const float &value)
|
||||||
|
|||||||
Reference in New Issue
Block a user