mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 11:03:33 +08:00
<limits> from STL is not required
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
#include <uavcan/stdint.hpp>
|
||||
#include <uavcan/data_type.hpp>
|
||||
@@ -18,6 +17,8 @@
|
||||
#endif
|
||||
#if UAVCAN_CPP_VERSION < UAVCAN_CPP11
|
||||
# include <math.h> // Needed for isfinite()
|
||||
#else
|
||||
# include <limits> // Assuming that in C++11 mode all standard headers are available
|
||||
#endif
|
||||
|
||||
namespace uavcan
|
||||
@@ -43,8 +44,10 @@ class UAVCAN_EXPORT IEEE754Converter
|
||||
IEEE754Converter();
|
||||
|
||||
public:
|
||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
||||
/// UAVCAN requires rounding to nearest for all float conversions
|
||||
static std::float_round_style roundstyle() { return std::round_to_nearest; }
|
||||
#endif
|
||||
|
||||
template <unsigned BitLen>
|
||||
static typename IntegerSpec<BitLen, SignednessUnsigned, CastModeTruncate>::StorageType
|
||||
@@ -118,11 +121,17 @@ public:
|
||||
|
||||
typedef typename NativeFloatSelector<BitLen>::Type StorageType;
|
||||
|
||||
#if UAVCAN_CPP_VERSION < UAVCAN_CPP11
|
||||
enum { IsExactRepresentation = (sizeof(StorageType) * 8 == BitLen) };
|
||||
#else
|
||||
enum { IsExactRepresentation = (sizeof(StorageType) * 8 == BitLen) && std::numeric_limits<StorageType>::is_iec559 };
|
||||
#endif
|
||||
|
||||
using IEEE754Limits<BitLen>::max;
|
||||
using IEEE754Limits<BitLen>::epsilon;
|
||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
||||
static std::float_round_style roundstyle() { return IEEE754Converter::roundstyle(); }
|
||||
#endif
|
||||
|
||||
static int encode(StorageType value, ScalarCodec& codec, TailArrayOptimizationMode)
|
||||
{
|
||||
@@ -180,11 +189,11 @@ private:
|
||||
{
|
||||
if (value > max())
|
||||
{
|
||||
value = std::numeric_limits<StorageType>::infinity();
|
||||
value = NumericTraits<StorageType>::infinity();
|
||||
}
|
||||
else if (value < -max())
|
||||
{
|
||||
value = -std::numeric_limits<StorageType>::infinity();
|
||||
value = -NumericTraits<StorageType>::infinity();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <uavcan/stdint.hpp>
|
||||
#include <uavcan/data_type.hpp>
|
||||
#include <uavcan/util/templates.hpp>
|
||||
@@ -93,9 +92,9 @@ private:
|
||||
{
|
||||
StaticAssert<(BitLen <= (sizeof(StorageType) * 8))>::check();
|
||||
// coverity[result_independent_of_operands : FALSE]
|
||||
assert(max() <= std::numeric_limits<StorageType>::max());
|
||||
assert(max() <= NumericTraits<StorageType>::max());
|
||||
// coverity[result_independent_of_operands : FALSE]
|
||||
assert(min() >= std::numeric_limits<StorageType>::min());
|
||||
assert(min() >= NumericTraits<StorageType>::min());
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
#include <uavcan/stdint.hpp>
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
#include <uavcan/util/templates.hpp>
|
||||
@@ -47,10 +46,10 @@ class UAVCAN_EXPORT ScalarCodec
|
||||
convertByteOrder(uint8_t (&)[Size]) { }
|
||||
|
||||
template <unsigned BitLen, typename T>
|
||||
static typename EnableIf<std::numeric_limits<T>::is_signed && ((sizeof(T) * 8) > BitLen)>::Type
|
||||
static typename EnableIf<static_cast<bool>(NumericTraits<T>::IsSigned) && ((sizeof(T) * 8) > BitLen)>::Type
|
||||
fixTwosComplement(T& value)
|
||||
{
|
||||
StaticAssert<std::numeric_limits<T>::is_integer>::check(); // Not applicable to floating point types
|
||||
StaticAssert<NumericTraits<T>::IsInteger>::check(); // Not applicable to floating point types
|
||||
if (value & (T(1) << (BitLen - 1))) // The most significant bit is set --> negative
|
||||
{
|
||||
value |= 0xFFFFFFFFFFFFFFFF & ~((T(1) << BitLen) - 1);
|
||||
@@ -58,7 +57,7 @@ class UAVCAN_EXPORT ScalarCodec
|
||||
}
|
||||
|
||||
template <unsigned BitLen, typename T>
|
||||
static typename EnableIf<!std::numeric_limits<T>::is_signed || ((sizeof(T) * 8) == BitLen)>::Type
|
||||
static typename EnableIf<!static_cast<bool>(NumericTraits<T>::IsSigned) || ((sizeof(T) * 8) == BitLen)>::Type
|
||||
fixTwosComplement(T&) { }
|
||||
|
||||
template <unsigned BitLen, typename T>
|
||||
@@ -77,7 +76,7 @@ class UAVCAN_EXPORT ScalarCodec
|
||||
{
|
||||
StaticAssert<((sizeof(T) * 8) >= BitLen)>::check();
|
||||
StaticAssert<(BitLen <= BitStream::MaxBitsPerRW)>::check();
|
||||
StaticAssert<std::numeric_limits<T>::is_signed ? (BitLen > 1) : 1>::check();
|
||||
StaticAssert<static_cast<bool>(NumericTraits<T>::IsSigned) ? (BitLen > 1) : true>::check();
|
||||
}
|
||||
|
||||
int encodeBytesImpl(uint8_t* bytes, unsigned bitlen);
|
||||
|
||||
Reference in New Issue
Block a user