diff --git a/src/ArduinoJson/Numbers/FloatTraits.hpp b/src/ArduinoJson/Numbers/FloatTraits.hpp index 1c4559d8..5a932f79 100644 --- a/src/ArduinoJson/Numbers/FloatTraits.hpp +++ b/src/ArduinoJson/Numbers/FloatTraits.hpp @@ -117,15 +117,6 @@ struct FloatTraits { return forge(0x7FEFFFFF, 0xFFFFFFFF); } - template - static - typename enable_if::value && sizeof(TOut) < sizeof(T), - T>::type - highest_for() { - // This conversion is safe because the destination type is smaller - return highest(); - } - template static typename enable_if::value && is_signed::value && sizeof(TOut) == 8, @@ -238,15 +229,6 @@ struct FloatTraits { return forge(0x7f7fffff); } - template - static - typename enable_if::value && sizeof(TOut) < sizeof(T), - T>::type - highest_for() { - // This conversion is safe because the destination type is smaller - return highest(); - } - template static typename enable_if::value && is_signed::value && sizeof(TOut) == 4, diff --git a/src/ArduinoJson/Numbers/convertNumber.hpp b/src/ArduinoJson/Numbers/convertNumber.hpp index 9bf54e8d..a9072a5c 100644 --- a/src/ArduinoJson/Numbers/convertNumber.hpp +++ b/src/ArduinoJson/Numbers/convertNumber.hpp @@ -96,21 +96,32 @@ canConvertNumber(TIn value) { return value <= TIn(numeric_limits::highest()); } -// float32 -> int16 -// float32 -> int32 -// float32 -> int64 // float32 -> int8 -// float32 -> uint32 -// float32 -> uint64 +// float32 -> int16 // float64 -> int32 -// float64 -> int64 -// float64 -> uint64 template -typename enable_if::value && is_integral::value, +typename enable_if::value && is_integral::value && + sizeof(TOut) < sizeof(TIn), bool>::type canConvertNumber(TIn value) { return value >= numeric_limits::lowest() && - value <= numeric_limits::highest() && + value <= numeric_limits::highest(); +} + +// float32 -> int32 +// float32 -> uint32 +// float32 -> int64 +// float32 -> uint64 +// float64 -> int64 +// float64 -> uint64 +template +typename enable_if::value && is_integral::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::lowest() && value <= FloatTraits::template highest_for(); }