fixing number->string for numbers within an ulp of round numbers

This commit is contained in:
Alex Shinn 2018-04-01 21:01:58 +09:00
parent 060cfd550e
commit f67f63d570

4
sexp.c
View file

@ -1931,9 +1931,9 @@ sexp sexp_write_one (sexp ctx, sexp obj, sexp out) {
#endif #endif
{ {
i = snprintf(numbuf, NUMBUF_LEN, "%.15lg", f); i = snprintf(numbuf, NUMBUF_LEN, "%.15lg", f);
if (i >= 15 && sscanf(numbuf, "%lg", &ftmp) == 1 && ftmp != f) { if (sscanf(numbuf, "%lg", &ftmp) == 1 && ftmp != f) {
i = snprintf(numbuf, NUMBUF_LEN, "%.16lg", f); i = snprintf(numbuf, NUMBUF_LEN, "%.16lg", f);
if (i >= 16 && sscanf(numbuf, "%lg", &ftmp) == 1 && ftmp != f) { if (sscanf(numbuf, "%lg", &ftmp) == 1 && ftmp != f) {
i = snprintf(numbuf, NUMBUF_LEN, "%.17lg", f); i = snprintf(numbuf, NUMBUF_LEN, "%.17lg", f);
} }
} }