diff --git a/AK/Math.h b/AK/Math.h index 8bb6c5a254a..185a4c2a700 100644 --- a/AK/Math.h +++ b/AK/Math.h @@ -1017,11 +1017,15 @@ constexpr T pow(T x, T y) template constexpr int clamp_to_int(T value) { - if (value >= NumericLimits::max()) { + if (value >= NumericLimits::max()) return NumericLimits::max(); - } else if (value <= NumericLimits::min()) { + + if (value <= NumericLimits::min()) return NumericLimits::min(); - } + + if constexpr (IsFloatingPoint) + return round_to(value); + return value; } diff --git a/Tests/LibWeb/Layout/expected/acid1.txt b/Tests/LibWeb/Layout/expected/acid1.txt index 6596d426c3e..f0259c7d50e 100644 --- a/Tests/LibWeb/Layout/expected/acid1.txt +++ b/Tests/LibWeb/Layout/expected/acid1.txt @@ -1,15 +1,15 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline - BlockContainer at (0,0) content-size 800x419.921875 [BFC] children: not-inline + BlockContainer at (0,0) content-size 800x420 [BFC] children: not-inline BlockContainer <(anonymous)> at (0,0) content-size 800x0 children: inline TextNode <#text> - BlockContainer at (20,20) content-size 480x379.921875 children: not-inline + BlockContainer at (20,20) content-size 480x380 children: not-inline BlockContainer <(anonymous)> at (20,20) content-size 480x0 children: inline TextNode <#text> BlockContainer
at (25,25) content-size 470x0 children: inline TextNode <#text> - BlockContainer
at (40,40) content-size 49.984375x280 floating [BFC] children: inline - line 0 width: 28.296875, height: 10, bottom: 10, baseline: 7.984375 - frag 0 from TextNode start: 0, length: 6, rect: [40,40 28.296875x10] + BlockContainer
at (40,40) content-size 50x280 floating [BFC] children: inline + line 0 width: 28.3125, height: 10, bottom: 10, baseline: 8 + frag 0 from TextNode start: 0, length: 6, rect: [40,40 28.3125x10] "toggle" TextNode <#text> TextNode <#text> @@ -19,55 +19,55 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline BlockContainer