mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-07 00:19:27 +00:00
AK: Fix formatting of negative whole fixed point numbers
Instead of `-2` we were printing `-2.1` Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
This commit is contained in:
parent
daacc5c6c2
commit
394529b7d0
|
@ -396,7 +396,7 @@ ErrorOr<void> FormatBuilder::put_fixed_point(
|
||||||
u64 scale = pow<u64>(10, precision);
|
u64 scale = pow<u64>(10, precision);
|
||||||
|
|
||||||
auto fraction = (scale * fraction_value) / fraction_one; // TODO: overflows
|
auto fraction = (scale * fraction_value) / fraction_one; // TODO: overflows
|
||||||
if (is_negative)
|
if (is_negative && fraction != 0)
|
||||||
fraction = scale - fraction;
|
fraction = scale - fraction;
|
||||||
|
|
||||||
size_t leading_zeroes = 0;
|
size_t leading_zeroes = 0;
|
||||||
|
|
|
@ -178,4 +178,8 @@ TEST_CASE(formatter)
|
||||||
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(-0.1)), "-0.100007"sv);
|
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(-0.1)), "-0.100007"sv);
|
||||||
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(-0.02)), "-0.020005"sv);
|
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(-0.02)), "-0.020005"sv);
|
||||||
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(-0.0000000005)), "0"sv);
|
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(-0.0000000005)), "0"sv);
|
||||||
|
|
||||||
|
EXPECT_EQ(DeprecatedString::formatted("{}", Type(-1)), "-1"sv);
|
||||||
|
EXPECT_EQ(DeprecatedString::formatted("{}", Type(-2)), "-2"sv);
|
||||||
|
EXPECT_EQ(DeprecatedString::formatted("{}", Type(-3)), "-3"sv);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue