fixed: #87 by removing unnecessary check
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 18 Dec 2023 04:42:00 +0000 (22:42 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 18 Dec 2023 04:42:00 +0000 (22:42 -0600)
core/conv/conv.onyx
tests/bugs/format_negative_other_base [new file with mode: 0644]
tests/bugs/format_negative_other_base.onyx [new file with mode: 0644]

index 80b96f35d81b4f2788e4226e144388be3f4b3a9d..90f24698a961dfa1f481128bcf9c3004867832e3 100644 (file)
@@ -148,7 +148,7 @@ str_to_f64 :: (s: &str) -> f64 {
 """
 i64_to_str :: (n: i64, base: u64, buf: [] u8, min_length := 0, prefix := false) -> str {
     is_neg := false;
-    if n < 0 && base == 10 {
+    if n < 0 {
         is_neg = true;
         n = -n;
     }
diff --git a/tests/bugs/format_negative_other_base b/tests/bugs/format_negative_other_base
new file mode 100644 (file)
index 0000000..09fc140
--- /dev/null
@@ -0,0 +1,3 @@
+-4660
+-1234
+-2844
diff --git a/tests/bugs/format_negative_other_base.onyx b/tests/bugs/format_negative_other_base.onyx
new file mode 100644 (file)
index 0000000..309d9a2
--- /dev/null
@@ -0,0 +1,11 @@
+package main
+
+use core
+
+main :: () {
+       a: i32 = -0x1234;
+
+       core.printf("{}\n", a);
+       core.printf("{x}\n", a);
+       core.printf("{b12}\n", a);
+}