// ArduinoJson - arduinojson.org // Copyright Benoit Blanchon 2014-2020 // MIT License #pragma once #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wconversion" #elif defined(__GNUC__) #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) #pragma GCC diagnostic push #endif #pragma GCC diagnostic ignored "-Wconversion" #endif #include #include #include #include namespace ARDUINOJSON_NAMESPACE { template typename enable_if::value && sizeof(TOut) <= sizeof(TIn), bool>::type canStorePositiveInteger(TIn value) { return value <= TIn(numeric_limits::highest()); } template typename enable_if::value && sizeof(TIn) < sizeof(TOut), bool>::type canStorePositiveInteger(TIn) { return true; } template typename enable_if::value, bool>::type canStorePositiveInteger(TIn) { return true; } template typename enable_if::value, bool>::type canStoreNegativeInteger(TIn) { return true; } template typename enable_if::value && is_signed::value && sizeof(TOut) <= sizeof(TIn), bool>::type canStoreNegativeInteger(TIn value) { return value <= TIn(numeric_limits::highest()) + 1; } template typename enable_if::value && is_signed::value && sizeof(TIn) < sizeof(TOut), bool>::type canStoreNegativeInteger(TIn) { return true; } template typename enable_if::value && is_unsigned::value, bool>::type canStoreNegativeInteger(TIn) { return false; } template TOut convertPositiveInteger(TIn value) { return canStorePositiveInteger(value) ? TOut(value) : 0; } template TOut convertNegativeInteger(TIn value) { return canStoreNegativeInteger(value) ? TOut(~value + 1) : 0; } template typename enable_if::value, TOut>::type convertFloat( TIn value) { return TOut(value); } template typename enable_if::value, TOut>::type convertFloat( TIn value) { return value >= numeric_limits::lowest() && value <= numeric_limits::highest() ? TOut(value) : 0; } } // namespace ARDUINOJSON_NAMESPACE #if defined(__clang__) #pragma clang diagnostic pop #elif defined(__GNUC__) #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) #pragma GCC diagnostic pop #endif #endif