1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 22:48:11 +00:00

LibWeb: Saturate result in PixelUnits::operator/

This commit is contained in:
Hendiadyoin1 2023-07-26 15:03:51 +02:00 committed by Alexander Kalenik
parent f9fc0505fb
commit 71f56d8697
2 changed files with 11 additions and 3 deletions

View file

@ -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)