Skip to content

Commit

Permalink
Use appropriate number of digits when dumping floating point numbers.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfonseca committed May 14, 2012
1 parent 9db0c7a commit 5f2245e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions common/trace_dump.cpp
Expand Up @@ -24,6 +24,8 @@
**************************************************************************/


#include <limits>

#include "formatter.hpp"
#include "trace_dump.hpp"

Expand Down Expand Up @@ -89,11 +91,15 @@ class Dumper : public Visitor
}

void visit(Float *node) {
std::streamsize oldPrecision = os.precision(std::numeric_limits<float>::digits10 + 1);
os << literal << node->value << normal;
os.precision(oldPrecision);
}

void visit(Double *node) {
std::streamsize oldPrecision = os.precision(std::numeric_limits<double>::digits10 + 1);
os << literal << node->value << normal;
os.precision(oldPrecision);
}

void visit(String *node) {
Expand Down
3 changes: 2 additions & 1 deletion retrace/json.hpp
Expand Up @@ -35,6 +35,7 @@
#include <wchar.h>

#include <iomanip>
#include <limits>
#include <ostream>
#include <string>

Expand Down Expand Up @@ -332,7 +333,7 @@ class JSONWriter
writeNull();
} else {
separator();
os << std::dec << std::setprecision(9) << n;
os << std::dec << std::setprecision(std::numeric_limits<T>::digits10 + 1) << n;
value = true;
space = ' ';
}
Expand Down

0 comments on commit 5f2245e

Please sign in to comment.