From d34e749f6ec9785b4fdd488e986b7fa32ea7f3fe Mon Sep 17 00:00:00 2001 From: David Xchel Morales Hurtado Date: Fri, 10 Jul 2026 21:45:05 -0600 Subject: [PATCH] Fixed {:c} formatting with negative integrals std::format uses the two's complement for formatting while FML used the absolute value, failing to correctly write when using values like -104 (FMT used 104 while std uses 152) --- include/fmt/format.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/fmt/format.h b/include/fmt/format.h index 57062792..29834cfb 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2124,6 +2124,10 @@ FMT_CONSTEXPR FMT_INLINE auto write_int(OutputIt out, write_int_arg arg, prefix_append(prefix, unsigned(specs.upper() ? 'B' : 'b') << 8 | '0'); break; case presentation_type::chr: + // Handles negative cases on casts to smaller types using Two's complement + // One example is int{-104} to char which std::format uses as 152 + if (sizeof(Char) < sizeof(abs_value) && (arg.prefix & 0xff) == '-') + abs_value = (1 << (8*sizeof(Char))) - abs_value; return write_char(out, static_cast(abs_value), specs); }