Skip to content

Commit

Permalink
Increase float precision when printing
Browse files Browse the repository at this point in the history
To avoid scientific notation.
Fixes #175
  • Loading branch information
erenon committed Jul 16, 2024
1 parent 6e69906 commit 65a5e3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/binlog/detail/OstreamBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ OstreamBuffer& OstreamBuffer::operator<<(bool b)
OstreamBuffer& OstreamBuffer::operator<<(double v)
{
reserve(64);
_p += snprintf(_p, 64, "%g", v);
_p += snprintf(_p, 64, "%.16g", v);
return *this;
}

OstreamBuffer& OstreamBuffer::operator<<(long double v)
{
reserve(128);
_p += snprintf(_p, 128, "%Lg", v);
_p += snprintf(_p, 128, "%.16Lg", v);
return *this;
}

Expand Down
12 changes: 12 additions & 0 deletions test/integration/LoggingFundamentals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ void logUnsigned()
BINLOG_INFO("{} {} {} {}", a, b, c, T(40));
}

template <typename T>
void logDouble()
{
T f = 1234234.0234242;
BINLOG_INFO("{}", f);
}

int main()
{
logSigned<signed short>(); // NOLINT
Expand Down Expand Up @@ -66,6 +73,11 @@ int main()
// Outputs: -20 30 30 -40
// Outputs: -20 30 30 -40

logDouble<double>();
logDouble<long double>();
// Outputs: 1234234.0234242
// Outputs: 1234234.0234242

char c = 'A';
const char cc = 'B';
const char& ccr = 'C';
Expand Down

0 comments on commit 65a5e3c

Please sign in to comment.