mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 00:38:27 +01:00
Reduce size
This commit is contained in:
@@ -117,15 +117,6 @@ struct FloatTraits<T, 8 /*64bits*/> {
|
|||||||
return forge(0x7FEFFFFF, 0xFFFFFFFF);
|
return forge(0x7FEFFFFF, 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TOut>
|
|
||||||
static
|
|
||||||
typename enable_if<is_integral<TOut>::value && sizeof(TOut) < sizeof(T),
|
|
||||||
T>::type
|
|
||||||
highest_for() {
|
|
||||||
// This conversion is safe because the destination type is smaller
|
|
||||||
return highest();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename TOut>
|
template <typename TOut>
|
||||||
static typename enable_if<is_integral<TOut>::value &&
|
static typename enable_if<is_integral<TOut>::value &&
|
||||||
is_signed<TOut>::value && sizeof(TOut) == 8,
|
is_signed<TOut>::value && sizeof(TOut) == 8,
|
||||||
@@ -238,15 +229,6 @@ struct FloatTraits<T, 4 /*32bits*/> {
|
|||||||
return forge(0x7f7fffff);
|
return forge(0x7f7fffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TOut>
|
|
||||||
static
|
|
||||||
typename enable_if<is_integral<TOut>::value && sizeof(TOut) < sizeof(T),
|
|
||||||
T>::type
|
|
||||||
highest_for() {
|
|
||||||
// This conversion is safe because the destination type is smaller
|
|
||||||
return highest();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename TOut>
|
template <typename TOut>
|
||||||
static typename enable_if<is_integral<TOut>::value &&
|
static typename enable_if<is_integral<TOut>::value &&
|
||||||
is_signed<TOut>::value && sizeof(TOut) == 4,
|
is_signed<TOut>::value && sizeof(TOut) == 4,
|
||||||
|
|||||||
@@ -96,21 +96,32 @@ canConvertNumber(TIn value) {
|
|||||||
return value <= TIn(numeric_limits<TOut>::highest());
|
return value <= TIn(numeric_limits<TOut>::highest());
|
||||||
}
|
}
|
||||||
|
|
||||||
// float32 -> int16
|
|
||||||
// float32 -> int32
|
|
||||||
// float32 -> int64
|
|
||||||
// float32 -> int8
|
// float32 -> int8
|
||||||
// float32 -> uint32
|
// float32 -> int16
|
||||||
// float32 -> uint64
|
|
||||||
// float64 -> int32
|
// float64 -> int32
|
||||||
// float64 -> int64
|
|
||||||
// float64 -> uint64
|
|
||||||
template <typename TOut, typename TIn>
|
template <typename TOut, typename TIn>
|
||||||
typename enable_if<is_floating_point<TIn>::value && is_integral<TOut>::value,
|
typename enable_if<is_floating_point<TIn>::value && is_integral<TOut>::value &&
|
||||||
|
sizeof(TOut) < sizeof(TIn),
|
||||||
bool>::type
|
bool>::type
|
||||||
canConvertNumber(TIn value) {
|
canConvertNumber(TIn value) {
|
||||||
return value >= numeric_limits<TOut>::lowest() &&
|
return value >= numeric_limits<TOut>::lowest() &&
|
||||||
value <= numeric_limits<TOut>::highest() &&
|
value <= numeric_limits<TOut>::highest();
|
||||||
|
}
|
||||||
|
|
||||||
|
// float32 -> int32
|
||||||
|
// float32 -> uint32
|
||||||
|
// float32 -> int64
|
||||||
|
// float32 -> uint64
|
||||||
|
// float64 -> int64
|
||||||
|
// float64 -> uint64
|
||||||
|
template <typename TOut, typename TIn>
|
||||||
|
typename enable_if<is_floating_point<TIn>::value && is_integral<TOut>::value &&
|
||||||
|
sizeof(TOut) >= sizeof(TIn),
|
||||||
|
bool>::type
|
||||||
|
canConvertNumber(TIn value) {
|
||||||
|
// Avoid error "9.22337e+18 is outside the range of representable values of
|
||||||
|
// type 'long'"
|
||||||
|
return value >= numeric_limits<TOut>::lowest() &&
|
||||||
value <= FloatTraits<TIn>::template highest_for<TOut>();
|
value <= FloatTraits<TIn>::template highest_for<TOut>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user