Do not use scientific notations when printing doubles in logs.

Closes BIT-1558.
This commit is contained in:
Robin Sommer 2016-05-23 14:42:13 -07:00
parent 3581ead0d9
commit d86bf15dbf
7 changed files with 197 additions and 5 deletions

View file

@ -4,6 +4,7 @@
#include <stdlib.h>
#include <errno.h>
#include <math.h>
#include "Desc.h"
#include "File.h"
@ -138,17 +139,22 @@ void ODesc::Add(uint64 u)
}
}
void ODesc::Add(double d)
void ODesc::Add(double d, bool no_exp)
{
if ( IsBinary() )
AddBytes(&d, sizeof(d));
else
{
char tmp[256];
modp_dtoa2(d, tmp, IsReadable() ? 6 : 8);
if ( no_exp )
modp_dtoa3(d, tmp, sizeof(tmp), IsReadable() ? 6 : 8);
else
modp_dtoa2(d, tmp, IsReadable() ? 6 : 8);
Add(tmp);
if ( d == double(int(d)) )
if ( nearbyint(d) == d && isfinite(d) && ! strchr(tmp, 'e') )
// disambiguate from integer
Add(".0");
}