From b4dc8587946d5300ae983c9c3cfc2d03f76ed746 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 1 Jun 2024 11:25:14 -0400 Subject: Change how floats are serialized --- builtins/util.h | 2 -- compile.c | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/builtins/util.h b/builtins/util.h index dc42d570..5b71fa2b 100644 --- a/builtins/util.h +++ b/builtins/util.h @@ -32,8 +32,6 @@ CORD CORD_asprintf(CORD fmt, ...); #define CORD_appendf(cord, fmt, ...) CORD_sprintf(cord, "%r" fmt, *(cord) __VA_OPT__(,) __VA_ARGS__) #define CORD_all(...) CORD_catn(sizeof((CORD[]){__VA_ARGS__})/sizeof(CORD), __VA_ARGS__) -#define asprintfa(...) ({ char *_buf = alloca(snprintf(0, 0, __VA_ARGS__)); sprintf(_buf, __VA_ARGS__); _buf; }) - #define REVERSE_LIST(list) do { \ __typeof(list) _prev = NULL; \ __typeof(list) _next = NULL; \ diff --git a/compile.c b/compile.c index e7bb14c7..b6e26c84 100644 --- a/compile.c +++ b/compile.c @@ -1025,10 +1025,7 @@ CORD compile(env_t *env, ast_t *ast) } case Int: return CORD_asprintf("I%ld(%ld)", Match(ast, Int)->bits, Match(ast, Int)->i); case Num: { - // HACK: since the cord library doesn't support the '%a' specifier, this workaround - // is necessary: - char *buf = asprintfa(Match(ast, Num)->bits == 64 ? "%a" : "%af", Match(ast, Num)->n); - return CORD_from_char_star(buf); + return CORD_asprintf(Match(ast, Num)->bits == 64 ? "%.9g" : "%.9gf", Match(ast, Num)->n); } case Length: { ast_t *expr = Match(ast, Length)->value; -- cgit v1.2.3