Use more precision in debug serialization, to help debugging of OOS errors
This was SVN commit r7689.
This commit is contained in:
parent
7cef282d06
commit
f6081101e7
@ -24,6 +24,7 @@
|
||||
#include "lib/secure_crt.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
/*
|
||||
* The output format here is intended to be compatible with YAML,
|
||||
@ -36,10 +37,10 @@
|
||||
// across platforms, we want to convert to a canonical form.
|
||||
// TODO: we just do e+0xx now; ought to handle varying precisions and inf and nan etc too
|
||||
template<typename T>
|
||||
std::string canonfloat(T value)
|
||||
std::string canonfloat(T value, size_t prec)
|
||||
{
|
||||
std::stringstream str;
|
||||
str << value;
|
||||
str << std::setprecision(prec) << value;
|
||||
std::string r = str.str();
|
||||
size_t e = r.find('e');
|
||||
if (e == r.npos) // no "e"
|
||||
@ -94,17 +95,17 @@ void CDebugSerializer::PutNumber(const char* name, uint32_t value)
|
||||
|
||||
void CDebugSerializer::PutNumber(const char* name, float value)
|
||||
{
|
||||
m_Stream << INDENT << name << ": " << canonfloat(value) << "\n";
|
||||
m_Stream << INDENT << name << ": " << canonfloat(value, 8) << "\n";
|
||||
}
|
||||
|
||||
void CDebugSerializer::PutNumber(const char* name, double value)
|
||||
{
|
||||
m_Stream << INDENT << name << ": " << canonfloat(value) << "\n";
|
||||
m_Stream << INDENT << name << ": " << canonfloat(value, 17) << "\n";
|
||||
}
|
||||
|
||||
void CDebugSerializer::PutNumber(const char* name, fixed value)
|
||||
{
|
||||
m_Stream << INDENT << name << ": " << canonfloat(value.ToDouble()) << "\n";
|
||||
m_Stream << INDENT << name << ": " << canonfloat(value.ToDouble(), 11) << "\n";
|
||||
}
|
||||
|
||||
void CDebugSerializer::PutBool(const char* name, bool value)
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include "BinarySerializer.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
class CStdSerializerImpl
|
||||
{
|
||||
NONCOPYABLE(CStdSerializerImpl);
|
||||
|
@ -104,8 +104,8 @@ public:
|
||||
serialize.NumberDouble_Unbounded("x", 1e-100);
|
||||
serialize.NumberFixed_Unbounded("x", fixed::FromDouble(1e4));
|
||||
TS_ASSERT_STR_EQUALS(stream.str(),
|
||||
"x: 10000\nx: 0.0001\nx: 100000\nx: 1e-05\nx: 1e+06\nx: 1e-06\nx: 1e+10\nx: 1e-10\n"
|
||||
"x: 10000\nx: 0.0001\nx: 100000\nx: 1e-05\nx: 1e+06\nx: 1e-06\nx: 1e+10\nx: 1e-10\nx: 1e+100\nx: 1e-100\n"
|
||||
"x: 10000\nx: 9.9999997e-05\nx: 100000\nx: 9.9999997e-06\nx: 1000000\nx: 1e-06\nx: 1e+10\nx: 1e-10\n"
|
||||
"x: 10000\nx: 0.0001\nx: 100000\nx: 1.0000000000000001e-05\nx: 1000000\nx: 9.9999999999999995e-07\nx: 10000000000\nx: 1e-10\nx: 1e+100\nx: 1e-100\n"
|
||||
"x: 10000\n"
|
||||
);
|
||||
}
|
||||
@ -126,7 +126,7 @@ public:
|
||||
"i32: -123\n"
|
||||
"u32: 4294967173\n"
|
||||
"float: 1e+30\n"
|
||||
"double: 1e+300\n"
|
||||
"double: 1.0000000000000001e+300\n"
|
||||
"fixed: 1234.5\n"
|
||||
"t: true\n"
|
||||
"f: false\n"
|
||||
|
Loading…
Reference in New Issue
Block a user