Commit e0ae477b by Jesse Beder

Switch default precision to one more than the number of digits allows.

See, e.g., http://stackoverflow.com/questions/4738768/printing-double-without-losing-precision.
parent 8c517bf0
...@@ -19,8 +19,8 @@ namespace YAML ...@@ -19,8 +19,8 @@ namespace YAML
m_seqFmt.set(Block); m_seqFmt.set(Block);
m_mapFmt.set(Block); m_mapFmt.set(Block);
m_mapKeyFmt.set(Auto); m_mapKeyFmt.set(Auto);
m_floatPrecision.set(6); m_floatPrecision.set(std::numeric_limits<float>::digits10 + 1);
m_doublePrecision.set(15); m_doublePrecision.set(std::numeric_limits<double>::digits10 + 1);
} }
EmitterState::~EmitterState() EmitterState::~EmitterState()
...@@ -367,7 +367,7 @@ namespace YAML ...@@ -367,7 +367,7 @@ namespace YAML
bool EmitterState::SetFloatPrecision(int value, FmtScope::value scope) bool EmitterState::SetFloatPrecision(int value, FmtScope::value scope)
{ {
if(value < 0 || value > std::numeric_limits<float>::digits10) if(value < 0 || value > std::numeric_limits<float>::digits10 + 1)
return false; return false;
_Set(m_floatPrecision, value, scope); _Set(m_floatPrecision, value, scope);
return true; return true;
...@@ -375,7 +375,7 @@ namespace YAML ...@@ -375,7 +375,7 @@ namespace YAML
bool EmitterState::SetDoublePrecision(int value, FmtScope::value scope) bool EmitterState::SetDoublePrecision(int value, FmtScope::value scope)
{ {
if(value < 0 || value > std::numeric_limits<double>::digits10) if(value < 0 || value > std::numeric_limits<double>::digits10 + 1)
return false; return false;
_Set(m_doublePrecision, value, scope); _Set(m_doublePrecision, value, scope);
return true; return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment