1
0
Fork 0
mirror of https://github.com/ultrajson/ultrajson.git synced 2024-04-26 07:35:16 +02:00

Match Python json output for exponents

This commit is contained in:
David W.H. Swenson 2020-11-11 14:41:51 +01:00
parent f26f9679f1
commit af699c3cd0
No known key found for this signature in database
GPG Key ID: D573FDAB784AA195
3 changed files with 7 additions and 2 deletions

View File

@ -336,7 +336,7 @@ typedef struct __JSONObjectDecoder
EXPORTFUNCTION JSOBJ JSON_DecodeObject(JSONObjectDecoder *dec, const char *buffer, size_t cbBuffer);
#define DCONV_DECIMAL_IN_SHORTEST_LOW -6
#define DCONV_DECIMAL_IN_SHORTEST_HIGH 21
#define DCONV_DECIMAL_IN_SHORTEST_HIGH 16
enum dconv_d2s_flags {
DCONV_D2S_NO_FLAGS = 0,

View File

@ -827,7 +827,7 @@ PyObject* objToJSON(PyObject* self, PyObject *args, PyObject *kwargs)
}
dconv_d2s_init(DCONV_D2S_EMIT_TRAILING_DECIMAL_POINT | DCONV_D2S_EMIT_TRAILING_ZERO_AFTER_POINT,
dconv_d2s_init(DCONV_D2S_EMIT_TRAILING_DECIMAL_POINT | DCONV_D2S_EMIT_TRAILING_ZERO_AFTER_POINT | DCONV_D2S_EMIT_POSITIVE_EXPONENT_SIGN,
csInf, csNan, 'e', DCONV_DECIMAL_IN_SHORTEST_LOW, DCONV_DECIMAL_IN_SHORTEST_HIGH, 0, 0);
PRINTMARK();

View File

@ -78,6 +78,11 @@ def test_double_long_decimal_issue():
assert sut == decoded
@pytest.mark.parametrize("val", [1e10, 1e15, 1e16, 1e20])
def test_encode_float_string_rep(val):
assert ujson.dumps(val) == json.dumps(val)
def test_encode_decode_long_decimal():
sut = {"a": -528656961.4399388}
encoded = ujson.dumps(sut)