mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
LibWeb: Fix a rounding issue on CSSPixels multiplication
Co-Authored-By: ronak69 <ronak69@danwin1210.de>
This commit is contained in:
parent
096cecb95e
commit
b342b4dfb8
Notes:
sideshowbarker
2024-07-16 22:26:05 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/b342b4dfb8 Pull-request: https://github.com/SerenityOS/serenity/pull/20639
@ -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)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user