diff --git a/CHANGELOG.md b/CHANGELOG.md index a5841598..d9525e96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to this project will be documented in this file. +## Unreleased - ??? +- Fix `%j` formatter to print numbers precisely (using the `%.17g` format string to printf). + ## 1.10.1 - 2020-06-18 - Expose `janet_table_clear` in API. - Respect `JANET_NO_PROCESSES` define when building diff --git a/meson.build b/meson.build index bcb0c07e..78625ec2 100644 --- a/meson.build +++ b/meson.build @@ -20,7 +20,7 @@ project('janet', 'c', default_options : ['c_std=c99', 'b_lundef=false', 'default_library=both'], - version : '1.10.1') + version : '1.10.2') # Global settings janet_path = join_paths(get_option('prefix'), get_option('libdir'), 'janet') diff --git a/src/conf/janetconf.h b/src/conf/janetconf.h index dc57b09b..2343666b 100644 --- a/src/conf/janetconf.h +++ b/src/conf/janetconf.h @@ -28,9 +28,9 @@ #define JANET_VERSION_MAJOR 1 #define JANET_VERSION_MINOR 10 -#define JANET_VERSION_PATCH 1 -#define JANET_VERSION_EXTRA "" -#define JANET_VERSION "1.10.1" +#define JANET_VERSION_PATCH 2 +#define JANET_VERSION_EXTRA "-dev" +#define JANET_VERSION "1.10.2-dev" /* #define JANET_BUILD "local" */ diff --git a/src/core/pp.c b/src/core/pp.c index 6c030b3a..59acba1b 100644 --- a/src/core/pp.c +++ b/src/core/pp.c @@ -123,9 +123,6 @@ static void string_description_b(JanetBuffer *buffer, const char *title, void *p #undef POINTSIZE } -#undef HEX -#undef BUFSIZE - static void janet_escape_string_impl(JanetBuffer *buffer, const uint8_t *str, int32_t len) { janet_buffer_push_u8(buffer, '"'); for (int32_t i = 0; i < len; ++i) { @@ -354,12 +351,16 @@ static int print_jdn_one(struct pretty *S, Janet x, int depth) { if (depth == 0) return 1; switch (janet_type(x)) { case JANET_NIL: - case JANET_NUMBER: case JANET_BOOLEAN: case JANET_BUFFER: case JANET_STRING: janet_description_b(S->buffer, x); break; + case JANET_NUMBER: + janet_buffer_ensure(S->buffer, S->buffer->count + BUFSIZE, 2); + int count = snprintf((char *) S->buffer->data + S->buffer->count, BUFSIZE, "%.17g", janet_unwrap_number(x)); + S->buffer->count += count; + break; case JANET_SYMBOL: case JANET_KEYWORD: if (contains_bad_chars(janet_unwrap_keyword(x), janet_type(x) == JANET_SYMBOL)) return 1; @@ -994,3 +995,6 @@ void janet_buffer_format( } } } + +#undef HEX +#undef BUFSIZE diff --git a/test/suite8.janet b/test/suite8.janet index 71f1b0ff..9cd6152f 100644 --- a/test/suite8.janet +++ b/test/suite8.janet @@ -307,4 +307,16 @@ neldb\0\0\0\xD8\x05printG\x01\0\xDE\xDE\xDE'\x03\0marshal_tes/\x02 (assert (:match peg5 "abcabcabcac") "repeat alias 2") (assert (not (:match peg5 "abcabc")) "repeat alias 3") +(defn check-jdn [x] + (assert (deep= (parse (string/format "%j" x)) x) "round trip jdn")) + +(check-jdn 0) +(check-jdn nil) +(check-jdn []) +(check-jdn @[[] [] 1231 9.123123 -123123 0.1231231230001]) +(check-jdn -0.123123123123) +(check-jdn 12837192371923) +(check-jdn "a string") +(check-jdn @"a buffer") + (end-suite)