mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
AK: Add Formatter<FixedPoint<...>> without floating point
Rather than casting the FixedPoint to double, format the FixedPoint directly. This avoids using floating point instruction, which in turn enables this to be used even in the kernel.
This commit is contained in:
parent
77b3230c80
commit
f021baf255
4 changed files with 124 additions and 15 deletions
|
@ -72,3 +72,12 @@ TEST_CASE(rounding)
|
|||
EXPECT_EQ(Type(-1.5).lceil(), -1);
|
||||
EXPECT_EQ(Type(-1.5).ltrunk(), -1);
|
||||
}
|
||||
|
||||
TEST_CASE(formatter)
|
||||
{
|
||||
EXPECT_EQ(String::formatted("{}", FixedPoint<16>(123.456)), "123.455993"sv);
|
||||
EXPECT_EQ(String::formatted("{}", FixedPoint<16>(-123.456)), "-123.455994"sv);
|
||||
EXPECT_EQ(String::formatted("{}", FixedPoint<4>(123.456)), "123.4375"sv);
|
||||
EXPECT_EQ(String::formatted("{}", FixedPoint<4>(-123.456)), "-123.4375"sv);
|
||||
EXPECT_EQ(String::formatted("{}", FixedPoint<16> {}), "0"sv);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue