Fixed precision issue that caused double->text->double round trip conversions to be inexact

This commit is contained in:
jean 2016-02-11 00:24:19 +01:00
parent a831c787df
commit 548a76e94a
2 changed files with 6 additions and 6 deletions

View File

@ -5986,10 +5986,10 @@ class basic_json
{ {
// If the number is an integer then output as a fixed with with // 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 // 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 // round-trip IEEE 754 string->double->string; to be safe, we
// read this value from // read this value from
// std::numeric_limits<number_float_t>::digits10 // std::numeric_limits<number_float_t>::max_digits10
if (std::fmod(m_value.number_float, 1) == 0) if (std::fmod(m_value.number_float, 1) == 0)
{ {
o << std::fixed << std::setprecision(1); o << std::fixed << std::setprecision(1);
@ -5998,7 +5998,7 @@ class basic_json
{ {
// std::defaultfloat not supported in gcc version < 5 // std::defaultfloat not supported in gcc version < 5
o.unsetf(std::ios_base::floatfield); o.unsetf(std::ios_base::floatfield);
o << std::setprecision(std::numeric_limits<double>::digits10); o << std::setprecision(std::numeric_limits<double>::max_digits10);
} }
o << m_value.number_float; o << m_value.number_float;
return; return;

View File

@ -5986,10 +5986,10 @@ class basic_json
{ {
// If the number is an integer then output as a fixed with with // 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 // 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 // round-trip IEEE 754 string->double->string; to be safe, we
// read this value from // read this value from
// std::numeric_limits<number_float_t>::digits10 // std::numeric_limits<number_float_t>::max_digits10
if (std::fmod(m_value.number_float, 1) == 0) if (std::fmod(m_value.number_float, 1) == 0)
{ {
o << std::fixed << std::setprecision(1); o << std::fixed << std::setprecision(1);
@ -5998,7 +5998,7 @@ class basic_json
{ {
// std::defaultfloat not supported in gcc version < 5 // std::defaultfloat not supported in gcc version < 5
o.unsetf(std::ios_base::floatfield); o.unsetf(std::ios_base::floatfield);
o << std::setprecision(std::numeric_limits<double>::digits10); o << std::setprecision(std::numeric_limits<double>::max_digits10);
} }
o << m_value.number_float; o << m_value.number_float;
return; return;