webmcp
changeset 189:44344b4a52c1
Increase precision of exported floats to 16 decimal digits in json.export(...)
author | jbe |
---|---|
date | Sun Aug 10 19:41:45 2014 +0200 (2014-08-10) |
parents | 433fa98329ec |
children | 2c0db49591be |
files | libraries/json/json.c |
line diff
1.1 --- a/libraries/json/json.c Sun Aug 10 19:18:25 2014 +0200 1.2 +++ b/libraries/json/json.c Sun Aug 10 19:41:45 2014 +0200 1.3 @@ -1021,6 +1021,7 @@ 1.4 int pretty; // pretty printing on? (i.e. printing with indentation) 1.5 luaL_Buffer buf; // Lua buffer containing result string 1.6 lua_Number num; // number to encode 1.7 + char numstr[20]; // encoded number (sign, zero, point, 16 significant digits, and terminating NULL byte) 1.8 const char *str; // string to encode 1.9 size_t strlen; // length of string to encode 1.10 size_t strpos ; // position in string or position of current key 1.11 @@ -1093,9 +1094,8 @@ 1.12 // throw error if number is positive or negative infinity: 1.13 if (isinf(num)) return luaL_error(L, "JSON export not possible for infinite numbers"); 1.14 // add Lua's string encoding of the number to the output buffer: 1.15 - lua_pushvalue(L, json_export_value_idx); 1.16 - lua_tostring(L, -1); 1.17 - luaL_addvalue(&buf); 1.18 + sprintf(numstr, "%.16g", num); 1.19 + luaL_addstring(&buf, numstr); 1.20 break; 1.21 // value to encode is of type boolean: 1.22 case LUA_TBOOLEAN: