mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-29 17:33:34 +08:00
Extra warnings for the debug build: -Wfloat-equal -Wconversion. The code was fixed accordingly. No broken tests.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user