From 52d593a9779d1c89e7b899ea48afec763cc1ae71 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sun, 17 Dec 2023 22:42:00 -0600 Subject: [PATCH] fixed: #87 by removing unnecessary check --- core/conv/conv.onyx | 2 +- tests/bugs/format_negative_other_base | 3 +++ tests/bugs/format_negative_other_base.onyx | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/bugs/format_negative_other_base create mode 100644 tests/bugs/format_negative_other_base.onyx diff --git a/core/conv/conv.onyx b/core/conv/conv.onyx index 80b96f35..90f24698 100644 --- a/core/conv/conv.onyx +++ b/core/conv/conv.onyx @@ -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 index 00000000..09fc1403 --- /dev/null +++ b/tests/bugs/format_negative_other_base @@ -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 index 00000000..309d9a27 --- /dev/null +++ b/tests/bugs/format_negative_other_base.onyx @@ -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); +} -- 2.25.1