mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 11:09:54 +00:00
Better roundtrip jdn.
Use the most precise format specifier, such that output jdn numbers are more accurate.
This commit is contained in:
parent
9cfc3d9d37
commit
5c364e0f7c
@ -1,6 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
All notable changes to this project will be documented in this file.
|
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
|
## 1.10.1 - 2020-06-18
|
||||||
- Expose `janet_table_clear` in API.
|
- Expose `janet_table_clear` in API.
|
||||||
- Respect `JANET_NO_PROCESSES` define when building
|
- Respect `JANET_NO_PROCESSES` define when building
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
project('janet', 'c',
|
project('janet', 'c',
|
||||||
default_options : ['c_std=c99', 'b_lundef=false', 'default_library=both'],
|
default_options : ['c_std=c99', 'b_lundef=false', 'default_library=both'],
|
||||||
version : '1.10.1')
|
version : '1.10.2')
|
||||||
|
|
||||||
# Global settings
|
# Global settings
|
||||||
janet_path = join_paths(get_option('prefix'), get_option('libdir'), 'janet')
|
janet_path = join_paths(get_option('prefix'), get_option('libdir'), 'janet')
|
||||||
|
@ -28,9 +28,9 @@
|
|||||||
|
|
||||||
#define JANET_VERSION_MAJOR 1
|
#define JANET_VERSION_MAJOR 1
|
||||||
#define JANET_VERSION_MINOR 10
|
#define JANET_VERSION_MINOR 10
|
||||||
#define JANET_VERSION_PATCH 1
|
#define JANET_VERSION_PATCH 2
|
||||||
#define JANET_VERSION_EXTRA ""
|
#define JANET_VERSION_EXTRA "-dev"
|
||||||
#define JANET_VERSION "1.10.1"
|
#define JANET_VERSION "1.10.2-dev"
|
||||||
|
|
||||||
/* #define JANET_BUILD "local" */
|
/* #define JANET_BUILD "local" */
|
||||||
|
|
||||||
|
@ -123,9 +123,6 @@ static void string_description_b(JanetBuffer *buffer, const char *title, void *p
|
|||||||
#undef POINTSIZE
|
#undef POINTSIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef HEX
|
|
||||||
#undef BUFSIZE
|
|
||||||
|
|
||||||
static void janet_escape_string_impl(JanetBuffer *buffer, const uint8_t *str, int32_t len) {
|
static void janet_escape_string_impl(JanetBuffer *buffer, const uint8_t *str, int32_t len) {
|
||||||
janet_buffer_push_u8(buffer, '"');
|
janet_buffer_push_u8(buffer, '"');
|
||||||
for (int32_t i = 0; i < len; ++i) {
|
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;
|
if (depth == 0) return 1;
|
||||||
switch (janet_type(x)) {
|
switch (janet_type(x)) {
|
||||||
case JANET_NIL:
|
case JANET_NIL:
|
||||||
case JANET_NUMBER:
|
|
||||||
case JANET_BOOLEAN:
|
case JANET_BOOLEAN:
|
||||||
case JANET_BUFFER:
|
case JANET_BUFFER:
|
||||||
case JANET_STRING:
|
case JANET_STRING:
|
||||||
janet_description_b(S->buffer, x);
|
janet_description_b(S->buffer, x);
|
||||||
break;
|
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_SYMBOL:
|
||||||
case JANET_KEYWORD:
|
case JANET_KEYWORD:
|
||||||
if (contains_bad_chars(janet_unwrap_keyword(x), janet_type(x) == JANET_SYMBOL)) return 1;
|
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
|
||||||
|
@ -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 (:match peg5 "abcabcabcac") "repeat alias 2")
|
||||||
(assert (not (:match peg5 "abcabc")) "repeat alias 3")
|
(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)
|
(end-suite)
|
||||||
|
Loading…
Reference in New Issue
Block a user