From 548a76e94a5013913681918f68462bf64c00aff3 Mon Sep 17 00:00:00 2001 From: jean Date: Thu, 11 Feb 2016 00:24:19 +0100 Subject: [PATCH] Fixed precision issue that caused double->text->double round trip conversions to be inexact --- src/json.hpp | 6 +++--- src/json.hpp.re2c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 5a51ef318..00dc4f6bd 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -5986,10 +5986,10 @@ class basic_json { // If the number is an integer then output as a fixed with with // precision 1 to output "0.0", "1.0" etc as expected for some - // round trip tests otherwise 15 digits of precision allows + // round trip tests otherwise 17 digits of precision allows // round-trip IEEE 754 string->double->string; to be safe, we // read this value from - // std::numeric_limits::digits10 + // std::numeric_limits::max_digits10 if (std::fmod(m_value.number_float, 1) == 0) { o << std::fixed << std::setprecision(1); @@ -5998,7 +5998,7 @@ class basic_json { // std::defaultfloat not supported in gcc version < 5 o.unsetf(std::ios_base::floatfield); - o << std::setprecision(std::numeric_limits::digits10); + o << std::setprecision(std::numeric_limits::max_digits10); } o << m_value.number_float; return; diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index dcd7b7ec1..383a2bf0b 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -5986,10 +5986,10 @@ class basic_json { // If the number is an integer then output as a fixed with with // precision 1 to output "0.0", "1.0" etc as expected for some - // round trip tests otherwise 15 digits of precision allows + // round trip tests otherwise 17 digits of precision allows // round-trip IEEE 754 string->double->string; to be safe, we // read this value from - // std::numeric_limits::digits10 + // std::numeric_limits::max_digits10 if (std::fmod(m_value.number_float, 1) == 0) { o << std::fixed << std::setprecision(1); @@ -5998,7 +5998,7 @@ class basic_json { // std::defaultfloat not supported in gcc version < 5 o.unsetf(std::ios_base::floatfield); - o << std::setprecision(std::numeric_limits::digits10); + o << std::setprecision(std::numeric_limits::max_digits10); } o << m_value.number_float; return;