mirror of
https://github.com/fmtlib/fmt.git
synced 2026-07-30 16:26:27 +08:00
Changed two's complement method
Now using logic operators instead of bit shifting
This commit is contained in:
parent
a612e331f3
commit
74c2d6cfe7
@ -2127,7 +2127,7 @@ FMT_CONSTEXPR FMT_INLINE auto write_int(OutputIt out, write_int_arg<T> arg,
|
||||
// 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;
|
||||
abs_value = ~abs_value + 1;
|
||||
return write_char<Char>(out, static_cast<Char>(abs_value), specs);
|
||||
}
|
||||
|
||||
|
||||
@ -1334,7 +1334,7 @@ TEST(format_test, format_int) {
|
||||
"invalid format specifier");
|
||||
check_unknown_types(42, "bBdoxXnLc", "integer");
|
||||
EXPECT_EQ(fmt::format("{:c}", static_cast<int>('x')), "x");
|
||||
EXPECT_EQ(fmt::format("{:c}", int(-136)), "x");
|
||||
EXPECT_EQ(fmt::format("{:c}", -136), "x");
|
||||
}
|
||||
|
||||
TEST(format_test, format_bin) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user