# HG changeset patch # User jbe # Date 1407694737 -7200 # Node ID 33c8f7029cfa22bf3c6801d719620db141ad03d0 # Parent e61bf25f3d04d5fe4cb337abc18d96222231094a Minimum decimal floating point precision of 16 in json.encode(...) diff -r e61bf25f3d04 -r 33c8f7029cfa libraries/json/json.c --- a/libraries/json/json.c Sun Aug 10 20:04:36 2014 +0200 +++ b/libraries/json/json.c Sun Aug 10 20:18:57 2014 +0200 @@ -1094,9 +1094,7 @@ // throw error if number is positive or negative infinity: if (isinf(num)) return luaL_error(L, "JSON export not possible for infinite numbers"); // determine necessary precision to represent double precision floating point number: - sprintf(numstr, "%.14g", num); - if (strtod(numstr, NULL) != num) sprintf(numstr, "%.15g", num); - if (strtod(numstr, NULL) != num) sprintf(numstr, "%.16g", num); + sprintf(numstr, "%.16g", num); if (strtod(numstr, NULL) != num) sprintf(numstr, "%.17g", num); // add string encoding of the number to the output buffer: luaL_addstring(&buf, numstr);