mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-27 05:05:32 +03:00
LibWeb: Saturate result in PixelUnits::operator/
This commit is contained in:
parent
f9fc0505fb
commit
71f56d8697
Notes:
sideshowbarker
2024-07-17 06:35:16 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/71f56d8697 Pull-request: https://github.com/SerenityOS/serenity/pull/20210 Reviewed-by: https://github.com/kalenikaliaksandr ✅
@ -31,6 +31,11 @@ TEST_CASE(division1)
|
||||
CSSPixels b(5);
|
||||
CSSPixels c = a / b;
|
||||
EXPECT_EQ(c, CSSPixels(2));
|
||||
|
||||
a = CSSPixels::from_raw(0x3FFF'FFFF); // int_max / 2
|
||||
b = 0.25;
|
||||
EXPECT(!a.might_be_saturated());
|
||||
EXPECT((a / b).might_be_saturated());
|
||||
}
|
||||
|
||||
TEST_CASE(multiplication1)
|
||||
|
@ -124,9 +124,12 @@ CSSPixels CSSPixels::operator*(CSSPixels const& other) const
|
||||
|
||||
CSSPixels CSSPixels::operator/(CSSPixels const& other) const
|
||||
{
|
||||
CSSPixels result;
|
||||
result.set_raw_value(static_cast<long long>(fixed_point_denominator) * raw_value() / other.raw_value());
|
||||
return result;
|
||||
i64 mult = raw_value();
|
||||
mult <<= fractional_bits;
|
||||
mult /= other.raw_value();
|
||||
|
||||
int int_value = AK::clamp_to_int(mult);
|
||||
return from_raw(int_value);
|
||||
}
|
||||
|
||||
CSSPixels& CSSPixels::operator+=(CSSPixels const& other)
|
||||
|
Loading…
Reference in New Issue
Block a user