Commit 5f8ca6e3 authored by Nikias Bassen's avatar Nikias Bassen

xplist: Fix dtostr() inserting ':' to output string when fractional part overflows

parent e1f85215
......@@ -107,9 +107,22 @@ static size_t dtostr(char *buf, size_t bufsize, double realval)
int64_t v;
size_t len;
size_t p;
double CORR = 0.0000005;
f = modf(f, &ip);
len = snprintf(buf, bufsize, "%s%"PRIi64, ((f < 0) && (ip >= 0)) ? "-" : "", (int64_t)ip);
v = (int64_t)ip;
if (f < 0) {
if (((int)((f - CORR) * -10.0f)) >= 10) {
v--;
f = 0;
}
} else {
if (((int)((f + CORR) * 10.0f)) >= 10) {
v++;
f = 0;
}
}
len = snprintf(buf, bufsize, "%s%"PRIi64, ((f < 0) && (ip >= 0)) ? "-" : "", v);
if (len >= bufsize) {
return 0;
}
......@@ -117,7 +130,7 @@ static size_t dtostr(char *buf, size_t bufsize, double realval)
if (f < 0) {
f *= -1;
}
f += 0.0000004;
f += CORR;
p = len;
buf[p++] = '.';
......
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