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>();
98 return nativeIeeeToHalf(value);
104 return halfToNativeIeee(value);
112 static NativeType
max() {
return static_cast<NativeType
>(65504.0); }
113 static NativeType
epsilon() {
return static_cast<NativeType
>(9.77e-04); }
118 static NativeType
max() {
return static_cast<NativeType
>(3.40282346638528859812e+38); }
119 static NativeType
epsilon() {
return static_cast<NativeType
>(1.19209289550781250000e-7); }
124 static NativeType
max() {
return static_cast<NativeType
>(1.79769313486231570815e+308L); }
125 static NativeType
epsilon() {
return static_cast<NativeType
>(2.22044604925031308085e-16L); }
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>
230 static void stream(Stream&
s,
const StorageType value,
int)
238 #endif // UAVCAN_MARSHAL_FLOAT_SPEC_HPP_INCLUDED
static void enforceIeee()
struct UAVCAN_EXPORT Select
static void saturate(StorageType &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
NativeFloatSelector< 64 >::Type NativeType
class UAVCAN_EXPORT YamlStreamer
NativeFloatSelector< 32 >::Type NativeType
static void extendDataTypeSignature(DataTypeSignature &)
static int encode(StorageType value, ScalarCodec &codec, TailArrayOptimizationMode)
UAVCAN_EXPORT const T & max(const T &a, const T &b)
static IntegerSpec< BitLen, SignednessUnsigned, CastModeTruncate >::StorageType toIeee(typename NativeFloatSelector< BitLen >::Type value)
NativeFloatSelector< BitLen >::Type StorageType
int encode(const T value)
static NativeFloatSelector< BitLen >::Type toNative(typename IntegerSpec< BitLen, SignednessUnsigned, CastModeTruncate >::StorageType value)
TailArrayOptimizationMode
static std::float_round_style roundstyle()
static void truncate(StorageType &value)
static NativeType epsilon()
FloatSpec< BitLen, CastMode >::StorageType StorageType
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
static int decode(StorageType &out_value, ScalarCodec &codec, TailArrayOptimizationMode)
static std::float_round_style roundstyle()
UAVCAN requires rounding to nearest for all float conversions.
NativeFloatSelector< 16 >::Type NativeType
static void stream(Stream &s, const StorageType value, int)
struct UAVCAN_EXPORT StaticAssert
static NativeType epsilon()
static NativeType epsilon()