Fixed dec symbol to correctly print negative numbers as well.
h3rald h3rald@h3rald.com
Wed, 18 Dec 2024 09:02:54 +0100
2 files changed,
5 insertions(+),
2 deletions(-)
M
scripts/test.hex
→
scripts/test.hex
@@ -219,6 +219,8 @@ (("t" chr) (error) try "Symbol 'chr' requires an integer" ==)
((() chr) (error) try "Symbol 'chr' requires an integer" ==) ;120 + (0xffffffff dec "-1" ==) + ) "tests" :
M
src/symbols.c
→
src/symbols.c
@@ -540,7 +540,6 @@ }
int hex_symbol_dec(hex_context_t *ctx) { - HEX_POP(ctx, a); if (a.type == HEX_TYPE_INVALID) {@@ -549,7 +548,9 @@ return 1;
} if (a.type == HEX_TYPE_INTEGER) { - return hex_push_string(ctx, hex_itoa_dec(a.data.int_value)); + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%d", a.data.int_value); + return hex_push_string(ctx, buffer); } hex_error(ctx, "Symbol 'dec' requires an integer"); HEX_FREE(ctx, a);