Fix float precision

Replaced

    std::numeric_limits<T>::digits10 + 1
with

    std::numeric_limits<T>::max_digits10

everywhere.
This commit is contained in:
Raoul Wols 2017-02-22 16:57:29 +01:00
parent bedb28fdb4
commit bb3b109101
2 changed files with 6 additions and 6 deletions

View File

@ -76,7 +76,7 @@ struct convert<const char*> {
template <std::size_t N>
struct convert<const char[N]> {
static Node encode(const char(&rhs)[N]) { return Node(rhs); }
static Node encode(const char (&rhs)[N]) { return Node(rhs); }
};
template <>
@ -93,7 +93,7 @@ struct convert<_Null> {
struct convert<type> { \
static Node encode(const type& rhs) { \
std::stringstream stream; \
stream.precision(std::numeric_limits<type>::digits10 + 1); \
stream.precision(std::numeric_limits<type>::max_digits10); \
stream << rhs; \
return Node(stream.str()); \
} \

View File

@ -24,8 +24,8 @@ EmitterState::EmitterState()
m_seqFmt.set(Block);
m_mapFmt.set(Block);
m_mapKeyFmt.set(Auto);
m_floatPrecision.set(std::numeric_limits<float>::digits10 + 1);
m_doublePrecision.set(std::numeric_limits<double>::digits10 + 1);
m_floatPrecision.set(std::numeric_limits<float>::max_digits10);
m_doublePrecision.set(std::numeric_limits<double>::max_digits10);
}
EmitterState::~EmitterState() {}
@ -349,7 +349,7 @@ bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope) {
}
bool EmitterState::SetFloatPrecision(std::size_t value, FmtScope::value scope) {
if (value > std::numeric_limits<float>::digits10 + 1)
if (value > std::numeric_limits<float>::max_digits10)
return false;
_Set(m_floatPrecision, value, scope);
return true;
@ -357,7 +357,7 @@ bool EmitterState::SetFloatPrecision(std::size_t value, FmtScope::value scope) {
bool EmitterState::SetDoublePrecision(std::size_t value,
FmtScope::value scope) {
if (value > std::numeric_limits<double>::digits10 + 1)
if (value > std::numeric_limits<double>::max_digits10)
return false;
_Set(m_doublePrecision, value, scope);
return true;