Extra warnings for the debug build: -Wfloat-equal -Wconversion. The code was fixed accordingly. No broken tests.

This commit is contained in:
Pavel Kirienko
2014-08-28 01:33:27 +04:00
parent 61c4f89ea3
commit 8240c7962b
26 changed files with 112 additions and 83 deletions
+11 -1
View File
@@ -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