1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

AK: Rename AK::FixedPoint::round to rint and fix a rounding error

`rint` is a more accurate name for the roudning mode as the fixme above
stated
This commit is contained in:
Hendiadyoin1 2023-07-25 17:53:30 +02:00 committed by Andrew Kaster
parent 05c959e40b
commit daacc5c6c2
Notes: sideshowbarker 2024-07-16 20:44:03 +09:00
3 changed files with 26 additions and 17 deletions

View file

@ -38,46 +38,51 @@ TEST_CASE(arithmetic)
TEST_CASE(rounding)
{
EXPECT_EQ(Type(0.5).round(), Type(0));
EXPECT_EQ(Type(0.5).rint(), Type(0));
EXPECT_EQ(Type(0.5).floor(), Type(0));
EXPECT_EQ(Type(0.5).ceil(), Type(1));
EXPECT_EQ(Type(0.75).trunc(), Type(0));
EXPECT_EQ(Type(1.5).round(), Type(2));
EXPECT_EQ(Type(1.5).rint(), Type(2));
EXPECT_EQ(Type(1.5).floor(), Type(1));
EXPECT_EQ(Type(1.5).ceil(), Type(2));
EXPECT_EQ(Type(1.25).trunc(), Type(1));
EXPECT_EQ(Type(-0.5).round(), Type(0));
EXPECT_EQ(Type(-0.5).rint(), Type(0));
EXPECT_EQ(Type(-0.5).floor(), Type(-1));
EXPECT_EQ(Type(-0.5).ceil(), Type(0));
EXPECT_EQ(Type(-0.75).trunc(), Type(0));
EXPECT_EQ(Type(-1.5).round(), Type(-2));
EXPECT_EQ(Type(-1.5).rint(), Type(-2));
EXPECT_EQ(Type(-1.5).floor(), Type(-2));
EXPECT_EQ(Type(-1.5).ceil(), Type(-1));
EXPECT_EQ(Type(-1.25).trunc(), Type(-1));
EXPECT_EQ(Type(0.5).lround(), 0);
EXPECT_EQ(Type(0.5).lrint(), 0);
EXPECT_EQ(Type(0.5).lfloor(), 0);
EXPECT_EQ(Type(0.5).lceil(), 1);
EXPECT_EQ(Type(0.5).ltrunc(), 0);
EXPECT_EQ(Type(1.5).lround(), 2);
EXPECT_EQ(Type(1.5).lrint(), 2);
EXPECT_EQ(Type(1.5).lfloor(), 1);
EXPECT_EQ(Type(1.5).lceil(), 2);
EXPECT_EQ(Type(1.5).ltrunc(), 1);
EXPECT_EQ(Type(-0.5).lround(), 0);
EXPECT_EQ(Type(-0.5).lrint(), 0);
EXPECT_EQ(Type(-0.5).lfloor(), -1);
EXPECT_EQ(Type(-0.5).lceil(), 0);
EXPECT_EQ(Type(-0.5).ltrunc(), 0);
EXPECT_EQ(Type(-1.5).lround(), -2);
EXPECT_EQ(Type(-1.5).lrint(), -2);
EXPECT_EQ(Type(-1.5).lfloor(), -2);
EXPECT_EQ(Type(-1.5).lceil(), -1);
EXPECT_EQ(Type(-1.5).ltrunc(), -1);
EXPECT_EQ(Type(-1.6).rint(), -2);
EXPECT_EQ(Type(-1.4).rint(), -1);
EXPECT_EQ(Type(1.6).rint(), 2);
EXPECT_EQ(Type(1.4).rint(), 1);
// Check that sRGB TRC curve parameters match the s15fixed16 values stored in Gimp's built-in profile.
// (This only requires that the FixedPoint<> constructor rounds before truncating to the fixed-point value,
// as it should anyways.)