From 7dd34f1572bf890ed2c415e0a0dd458fb3b06375 Mon Sep 17 00:00:00 2001 From: Rangi Date: Wed, 17 Feb 2021 09:41:36 -0500 Subject: [PATCH] Format INT32_MIN as '-2147483648', not '--2147483648' --- src/asm/format.c | 5 ++--- test/asm/minimum-int.asm | 8 ++++++++ test/asm/minimum-int.err | 0 test/asm/minimum-int.out | 3 +++ 4 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 test/asm/minimum-int.asm create mode 100644 test/asm/minimum-int.err create mode 100644 test/asm/minimum-int.out diff --git a/src/asm/format.c b/src/asm/format.c index 1a38aa56..456cfc25 100644 --- a/src/asm/format.c +++ b/src/asm/format.c @@ -182,10 +182,9 @@ void fmt_PrintNumber(char *buf, size_t bufLen, struct FormatSpec const *fmt, uin if (fmt->type == 'd' || fmt->type == 'f') { int32_t v = value; - if (v < 0) { + if (v < 0 && v != INT32_MIN) { sign = '-'; - if (v != INT32_MIN) - value = -v; + value = -v; } } diff --git a/test/asm/minimum-int.asm b/test/asm/minimum-int.asm new file mode 100644 index 00000000..5c3cfc66 --- /dev/null +++ b/test/asm/minimum-int.asm @@ -0,0 +1,8 @@ +m = $8000_0000 +assert m == 1 << 31 +assert m == -(1 << 31) +assert m == (-2)**31 + + println "{m}" + println "({12d:m})" + println "({-12d:m})" diff --git a/test/asm/minimum-int.err b/test/asm/minimum-int.err new file mode 100644 index 00000000..e69de29b diff --git a/test/asm/minimum-int.out b/test/asm/minimum-int.out new file mode 100644 index 00000000..a36897da --- /dev/null +++ b/test/asm/minimum-int.out @@ -0,0 +1,3 @@ +$80000000 +( -2147483648) +(-2147483648 )