mirror of
https://github.com/nlohmann/json.git
synced 2025-07-28 12:02:00 +03:00
Add workaround for gcc < 5 not supporting std::defaultfloat
This commit is contained in:
@ -5544,7 +5544,10 @@ class basic_json
|
|||||||
// 15 digits of precision allows round-trip IEEE 754 string->double->string;
|
// 15 digits of precision allows round-trip IEEE 754 string->double->string;
|
||||||
// to be safe, we read this value from std::numeric_limits<number_float_t>::digits10
|
// to be safe, we read this value from std::numeric_limits<number_float_t>::digits10
|
||||||
if (std::fmod(m_value.number_float, 1) == 0) o << std::fixed << std::setprecision(1);
|
if (std::fmod(m_value.number_float, 1) == 0) o << std::fixed << std::setprecision(1);
|
||||||
else o << std::defaultfloat << std::setprecision(std::numeric_limits<double>::digits10);
|
else {
|
||||||
|
o.unsetf(std::ios_base::floatfield); // std::defaultfloat not supported in gcc version < 5
|
||||||
|
o << std::setprecision(std::numeric_limits<double>::digits10);
|
||||||
|
}
|
||||||
o << m_value.number_float;
|
o << m_value.number_float;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -5544,7 +5544,10 @@ class basic_json
|
|||||||
// 15 digits of precision allows round-trip IEEE 754 string->double->string;
|
// 15 digits of precision allows round-trip IEEE 754 string->double->string;
|
||||||
// to be safe, we read this value from std::numeric_limits<number_float_t>::digits10
|
// to be safe, we read this value from std::numeric_limits<number_float_t>::digits10
|
||||||
if (std::fmod(m_value.number_float, 1) == 0) o << std::fixed << std::setprecision(1);
|
if (std::fmod(m_value.number_float, 1) == 0) o << std::fixed << std::setprecision(1);
|
||||||
else o << std::defaultfloat << std::setprecision(std::numeric_limits<double>::digits10);
|
else {
|
||||||
|
o.unsetf(std::ios_base::floatfield); // std::defaultfloat not supported in gcc version < 5
|
||||||
|
o << std::setprecision(std::numeric_limits<double>::digits10);
|
||||||
|
}
|
||||||
o << m_value.number_float;
|
o << m_value.number_float;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user