From d2771eb1bb98827f992a7c7d3c05da484e67b6dc Mon Sep 17 00:00:00 2001 From: Florian Weber Date: Sun, 26 Apr 2015 14:39:39 +0200 Subject: [PATCH] Fix comparission between integers and floats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Until now it depended on the parameter-order whether integers and floats were compared as integers or floats. Appart from being not logical, this might even have meant that the provided “order” was in fact not that. (not sure here, but I like to be carefull) --- src/json.hpp | 8 ++++---- src/json.hpp.re2c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 67bfcea61..8a4ad12d9 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -1906,8 +1906,8 @@ class basic_json } else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float) { - return lhs.m_value.number_integer == - static_cast(rhs.m_value.number_float); + return approx(static_cast(lhs.m_value.number_integer), + rhs.m_value.number_float); } else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer) { @@ -1967,8 +1967,8 @@ class basic_json } else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float) { - return lhs.m_value.number_integer < - static_cast(rhs.m_value.number_float); + return static_cast(lhs.m_value.number_integer) < + rhs.m_value.number_float; } else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer) { diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 16139cae0..1d41b39c9 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -1906,8 +1906,8 @@ class basic_json } else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float) { - return lhs.m_value.number_integer == - static_cast(rhs.m_value.number_float); + return approx(static_cast(lhs.m_value.number_integer), + rhs.m_value.number_float); } else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer) { @@ -1967,8 +1967,8 @@ class basic_json } else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float) { - return lhs.m_value.number_integer < - static_cast(rhs.m_value.number_float); + return static_cast(lhs.m_value.number_integer) < + rhs.m_value.number_float; } else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer) {