mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-24 02:13:33 +08:00
Extra warnings for the debug build: -Wfloat-equal -Wconversion. The code was fixed accordingly. No broken tests.
This commit is contained in:
@@ -94,11 +94,11 @@ public:
|
||||
validatePos(pos);
|
||||
if (val)
|
||||
{
|
||||
data_[getByteNum(pos)] |= (1 << getBitNum(pos));
|
||||
data_[getByteNum(pos)] = char(data_[getByteNum(pos)] | (1 << getBitNum(pos)));
|
||||
}
|
||||
else
|
||||
{
|
||||
data_[getByteNum(pos)] &= ~(1 << getBitNum(pos));
|
||||
data_[getByteNum(pos)] = char(data_[getByteNum(pos)] & ~(1 << getBitNum(pos)));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,16 @@
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
/**
|
||||
* Exact comparison of two floats that suppresses the compiler warnings.
|
||||
*/
|
||||
template <typename T>
|
||||
UAVCAN_EXPORT
|
||||
inline bool areFloatsExactlyEqual(const T& left, const T& right)
|
||||
{
|
||||
return (left <= right) && (left >= right);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function performs fuzzy comparison of two floating point numbers.
|
||||
* Type of T can be either float, double or long double.
|
||||
@@ -27,7 +37,7 @@ inline bool areFloatsClose(T a, T b, const T absolute_epsilon, const T relative_
|
||||
// Infinity
|
||||
if (isInfinity(a) || isInfinity(b))
|
||||
{
|
||||
return a == b;
|
||||
return areFloatsExactlyEqual(a, b);
|
||||
}
|
||||
|
||||
// Close numbers near zero
|
||||
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
LazyConstructor()
|
||||
: ptr_(NULL)
|
||||
{
|
||||
fill(data_.pool, data_.pool + sizeof(T), 0);
|
||||
fill(data_.pool, data_.pool + sizeof(T), uint8_t(0));
|
||||
}
|
||||
|
||||
LazyConstructor(const LazyConstructor<T>& rhs) // Implicit
|
||||
@@ -102,7 +102,7 @@ public:
|
||||
ptr_->~T();
|
||||
}
|
||||
ptr_ = NULL;
|
||||
fill(data_.pool, data_.pool + sizeof(T), 0);
|
||||
fill(data_.pool, data_.pool + sizeof(T), uint8_t(0));
|
||||
}
|
||||
|
||||
void construct()
|
||||
|
||||
@@ -429,7 +429,8 @@ struct UAVCAN_EXPORT NumericTraits<long double>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Replacement for std::isnan()
|
||||
* Replacement for std::isnan().
|
||||
* Note that direct float comparison (==, !=) is intentionally avoided.
|
||||
*/
|
||||
template <typename T>
|
||||
inline bool isNaN(T arg)
|
||||
@@ -439,12 +440,13 @@ inline bool isNaN(T arg)
|
||||
#else
|
||||
// coverity[same_on_both_sides : FALSE]
|
||||
// cppcheck-suppress duplicateExpression
|
||||
return arg != arg;
|
||||
return !(arg <= arg);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Replacement for std::isinf()
|
||||
* Replacement for std::isinf().
|
||||
* Note that direct float comparison (==, !=) is intentionally avoided.
|
||||
*/
|
||||
template <typename T>
|
||||
inline bool isInfinity(T arg)
|
||||
@@ -452,12 +454,13 @@ inline bool isInfinity(T arg)
|
||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
||||
return std::isinf(arg);
|
||||
#else
|
||||
return arg == NumericTraits<T>::infinity() || arg == -NumericTraits<T>::infinity();
|
||||
return (arg >= NumericTraits<T>::infinity()) || (arg <= -NumericTraits<T>::infinity());
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Replacement for std::signbit()
|
||||
* Replacement for std::signbit().
|
||||
* Note that direct float comparison (==, !=) is intentionally avoided.
|
||||
*/
|
||||
template <typename T>
|
||||
inline bool getSignBit(T arg)
|
||||
@@ -465,7 +468,7 @@ inline bool getSignBit(T arg)
|
||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
||||
return std::signbit(arg);
|
||||
#else
|
||||
return arg < T(0) || (arg == T(0) && T(1) / arg < T(0));
|
||||
return arg < T(0) || (((arg <= T(0)) && (arg >= T(0))) && (T(1) / arg < T(0)));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user