LibWeb: Fix a rounding issue on CSSPixels multiplication

Co-Authored-By: ronak69 <ronak69@danwin1210.de>
This commit is contained in:
Hendiadyoin1 2023-08-18 16:09:11 +02:00 committed by Alexander Kalenik
parent 096cecb95e
commit b342b4dfb8
Notes: sideshowbarker 2024-07-16 22:26:05 +09:00
2 changed files with 9 additions and 2 deletions

View file

@ -55,6 +55,13 @@ TEST_CASE(multiplication1)
b = CSSPixels::from_raw(0b01'100000);
EXPECT_EQ(a * b, CSSPixels(a.to_double() * b.to_double()));
EXPECT_EQ(a * -b, CSSPixels(a.to_double() * -b.to_double()));
EXPECT_EQ(
CSSPixels::from_raw(0b01'0000011) * CSSPixels::from_raw(0b00'010000),
CSSPixels::from_raw(0b00'0100001));
EXPECT_EQ(
CSSPixels::from_raw(0b01'0000111) * CSSPixels::from_raw(0b00'010000),
CSSPixels::from_raw(0b00'0100010));
}
TEST_CASE(addition2)

View file

@ -170,8 +170,8 @@ public:
// Rounding:
// If last bit cut off was 1:
if (value & (1u << (fractional_bits - 1))) {
// If the bit after was 1 as well
if (value & (radix_mask >> 2u)) {
// If any bit after was 1 as well
if (value & (radix_mask >> 1u)) {
// We need to round away from 0
int_value = Checked<int>::saturating_add(int_value, 1);
} else {