mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 03:43: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:
@@ -34,7 +34,7 @@ struct UAVCAN_EXPORT CanFrame
|
||||
: id(0)
|
||||
, dlc(0)
|
||||
{
|
||||
fill(data, data + MaxDataLen, 0);
|
||||
fill(data, data + MaxDataLen, uint8_t(0));
|
||||
}
|
||||
|
||||
CanFrame(uint32_t can_id, const uint8_t* can_data, uint8_t data_len)
|
||||
|
||||
@@ -530,7 +530,7 @@ public:
|
||||
void push_back(const ValueType& value)
|
||||
{
|
||||
Base::grow();
|
||||
Base::at(size() - 1) = value;
|
||||
Base::at(SizeType(size() - 1)) = value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -90,21 +90,25 @@ IEEE754Converter::toNative<16>(typename IntegerSpec<16, SignednessUnsigned, Cast
|
||||
return halfToNativeNonIeee(value);
|
||||
}
|
||||
|
||||
|
||||
template <unsigned BitLen> struct IEEE754Limits;
|
||||
template <> struct IEEE754Limits<16>
|
||||
{
|
||||
static typename NativeFloatSelector<16>::Type max() { return 65504.0; }
|
||||
static typename NativeFloatSelector<16>::Type epsilon() { return 9.77e-04; }
|
||||
typedef typename NativeFloatSelector<16>::Type NativeType;
|
||||
static NativeType max() { return static_cast<NativeType>(65504.0); }
|
||||
static NativeType epsilon() { return static_cast<NativeType>(9.77e-04); }
|
||||
};
|
||||
template <> struct IEEE754Limits<32>
|
||||
{
|
||||
static typename NativeFloatSelector<32>::Type max() { return 3.40282346638528859812e+38; }
|
||||
static typename NativeFloatSelector<32>::Type epsilon() { return 1.19209289550781250000e-7; }
|
||||
typedef typename NativeFloatSelector<32>::Type NativeType;
|
||||
static NativeType max() { return static_cast<NativeType>(3.40282346638528859812e+38); }
|
||||
static NativeType epsilon() { return static_cast<NativeType>(1.19209289550781250000e-7); }
|
||||
};
|
||||
template <> struct IEEE754Limits<64>
|
||||
{
|
||||
static typename NativeFloatSelector<64>::Type max() { return 1.79769313486231570815e+308L; }
|
||||
static typename NativeFloatSelector<64>::Type epsilon() { return 2.22044604925031308085e-16L; }
|
||||
typedef typename NativeFloatSelector<64>::Type NativeType;
|
||||
static NativeType max() { return static_cast<NativeType>(1.79769313486231570815e+308L); }
|
||||
static NativeType epsilon() { return static_cast<NativeType>(2.22044604925031308085e-16L); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
bool isLast() const { return last_frame_; }
|
||||
|
||||
void makeLast() { last_frame_ = true; }
|
||||
void setIndex(uint_fast8_t index) { frame_index_ = index; }
|
||||
void setIndex(int index) { frame_index_ = uint_fast8_t(index); }
|
||||
|
||||
bool isFirst() const { return frame_index_ == 0; }
|
||||
|
||||
|
||||
@@ -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