From 5dd27f1a9f8e9ff480ebbfea5e6fd4de40467dad Mon Sep 17 00:00:00 2001 From: chenguoping Date: Fri, 15 May 2020 21:47:59 +0800 Subject: [PATCH] compare against max float and min float before converting --- include/nlohmann/detail/output/binary_writer.hpp | 4 ++-- single_include/nlohmann/json.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index b8b5a572..163e88d9 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -194,8 +194,8 @@ class binary_writer } else { - if (j.m_value.number_float > -std::numeric_limits::min() and - j.m_value.number_float < std::numeric_limits::max() and + if (j.m_value.number_float >= std::numeric_limits::lowest() and + j.m_value.number_float <= std::numeric_limits::max() and static_cast(static_cast(j.m_value.number_float)) == j.m_value.number_float) { oa->write_character(get_cbor_float_prefix(static_cast(j.m_value.number_float))); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 23ae8105..b30e4560 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -12143,8 +12143,8 @@ class binary_writer } else { - if (j.m_value.number_float > -std::numeric_limits::min() and - j.m_value.number_float < std::numeric_limits::max() and + if (j.m_value.number_float >= std::numeric_limits::lowest() and + j.m_value.number_float <= std::numeric_limits::max() and static_cast(static_cast(j.m_value.number_float)) == j.m_value.number_float) { oa->write_character(get_cbor_float_prefix(static_cast(j.m_value.number_float)));