Go to the documentation of this file.
5 #ifndef UAVCAN_MARSHAL_FLOAT_SPEC_HPP_INCLUDED
6 #define UAVCAN_MARSHAL_FLOAT_SPEC_HPP_INCLUDED
16 #ifndef UAVCAN_CPP_VERSION
17 # error UAVCAN_CPP_VERSION
19 #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
26 template <
unsigned BitLen>
29 struct ErrorNoSuchFloat;
30 typedef typename Select<(
sizeof(float) * 8 >= BitLen), float,
31 typename Select<(
sizeof(double) * 8 >= BitLen), double,
32 typename Select<(
sizeof(
long double) * 8 >= BitLen),
long double,
33 ErrorNoSuchFloat>::Result>::Result>::Result
Type;
41 static uint16_t nativeIeeeToHalf(
float value);
42 static float halfToNativeIeee(
uint16_t value);
46 template <
unsigned BitLen>
53 #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
54 StaticAssert<std::numeric_limits<typename NativeFloatSelector<BitLen>::Type>::is_iec559>::check();
59 #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
60 static std::float_round_style roundstyle() {
return std::round_to_nearest; }
64 template <
unsigned BitLen>
68 enforceIeee<BitLen>();
79 template <
unsigned BitLen>
83 enforceIeee<BitLen>();
129 template <
unsigned BitLen_, CastMode CastMode>
135 enum { BitLen = BitLen_ };
136 enum { MinBitLen = BitLen };
137 enum { MaxBitLen = BitLen };
138 enum { IsPrimitive = 1 };
142 #if UAVCAN_CPP_VERSION < UAVCAN_CPP11
143 enum { IsExactRepresentation = (
sizeof(
StorageType) * 8 == BitLen) };
145 enum { IsExactRepresentation = (
sizeof(
StorageType) * 8 == BitLen) && std::numeric_limits<StorageType>::is_iec559 };
150 #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
165 return codec.
encode<BitLen>(IEEE754Converter::toIeee<BitLen>(value));
171 const int res = codec.
decode<BitLen>(ieee);
176 out_value = IEEE754Converter::toNative<BitLen>(ieee);
185 if ((IsExactRepresentation == 0) &&
isFinite(value))
191 else if (value < -
max())
204 if ((IsExactRepresentation == 0) &&
isFinite(value))
208 value = NumericTraits<StorageType>::infinity();
210 else if (value < -
max())
212 value = -NumericTraits<StorageType>::infinity();
223 template <
unsigned BitLen, CastMode CastMode>
229 template <
typename Stream>
238 #endif // UAVCAN_MARSHAL_FLOAT_SPEC_HPP_INCLUDED
static void stream(Stream &s, const StorageType value, int)
TailArrayOptimizationMode
static std::float_round_style roundstyle()
FloatSpec< BitLen, CastMode >::StorageType StorageType
static NativeType epsilon()
Select<(sizeof(float) *8 >=BitLen), float, typename Select<(sizeof(double) *8 >=BitLen), double, typename Select<(sizeof(long double) *8 >=BitLen), long double, ErrorNoSuchFloat >::Result >::Result >::Result Type
NativeFloatSelector< 16 >::Type NativeType
static IntegerSpec< BitLen, SignednessUnsigned, CastModeTruncate >::StorageType toIeee(typename NativeFloatSelector< BitLen >::Type value)
NativeFloatSelector< BitLen >::Type StorageType
static std::float_round_style roundstyle()
UAVCAN requires rounding to nearest for all float conversions.
static float halfToNativeIeee(uint16_t value)
Select<(BitLen<=8), typename Select< IsSigned, int8_t, uint8_t >::Result, typename Select<(BitLen<=16), typename Select< IsSigned, int16_t, uint16_t >::Result, typename Select<(BitLen<=32), typename Select< IsSigned, int32_t, uint32_t >::Result, typename Select<(BitLen<=64), typename Select< IsSigned, int64_t, uint64_t >::Result, ErrorNoSuchInteger >::Result >::Result >::Result >::Result StorageType
struct UAVCAN_EXPORT StaticAssert
static NativeFloatSelector< BitLen >::Type toNative(typename IntegerSpec< BitLen, SignednessUnsigned, CastModeTruncate >::StorageType value)
static int encode(StorageType value, ScalarCodec &codec, TailArrayOptimizationMode)
static void truncate(StorageType &value)
const UAVCAN_EXPORT T & max(const T &a, const T &b)
static uint16_t nativeIeeeToHalf(float value)
NativeFloatSelector< 32 >::Type NativeType
static void enforceIeee()
struct UAVCAN_EXPORT Select
static int decode(StorageType &out_value, ScalarCodec &codec, TailArrayOptimizationMode)
static NativeType epsilon()
static void saturate(StorageType &value)
class UAVCAN_EXPORT YamlStreamer
static void extendDataTypeSignature(DataTypeSignature &)
NativeFloatSelector< 64 >::Type NativeType
static NativeType epsilon()
int encode(const T value)