# HG changeset patch # User jbe # Date 1452793391 -3600 # Node ID 33d43f5a319bb9b8b007c0caa51dc7df05f04a58 # Parent 387a303918a6b94ae880c87ce6f00038db289693 json.export(...): Avoid exponential representation for integral floats when they could fit into a 64 bit integer diff -r 387a303918a6 -r 33d43f5a319b libraries/json/json.c --- a/libraries/json/json.c Thu Jan 14 18:01:33 2016 +0100 +++ b/libraries/json/json.c Thu Jan 14 18:43:11 2016 +0100 @@ -1121,8 +1121,14 @@ if (isinf(num)) return luaL_error(L, "JSON export not possible for infinite numbers"); // check if float is integral: if (trunc(num) == num) { - // if yes, use maximum precision: - sprintf(numstr, "%.17g", num); // NOTE: e.g. 12345678901234560 + // avoid exponential notation for INT64's represented as float: + if (fabs(num) < 1e19) { + // use decimal notation: + sprintf(numstr, "%.0f", num); + } else { + // use maximum precision: + sprintf(numstr, "%.17g", num); // NOTE: e.g. 12345678901234560 + } } else { // determine necessary precision to represent double precision floating point number: sprintf(numstr, "%.15g", num); // NOTE: e.g. 0.009 should not be 0.008999999999999999