mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 13:43:45 +03:00
AK: Use wider type for FixedPoint division
This allows us to shift first and then divide, preserving more precision
This commit is contained in:
parent
e609ac74a3
commit
8526791617
Notes:
sideshowbarker
2024-07-17 14:33:07 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/8526791617 Pull-request: https://github.com/SerenityOS/serenity/pull/20163 Reviewed-by: https://github.com/DanShaders
@ -226,8 +226,14 @@ public:
|
||||
}
|
||||
constexpr This operator/(This const& other) const
|
||||
{
|
||||
// FIXME: Better rounding?
|
||||
return create_raw((m_value / other.m_value) << (precision));
|
||||
// FIXME: Figure out a way to use more narrow types and avoid __int128
|
||||
using DivRes = Conditional<sizeof(Underlying) < sizeof(i64), i64, __int128>;
|
||||
|
||||
DivRes value = raw();
|
||||
value <<= precision;
|
||||
value /= other.raw();
|
||||
|
||||
return create_raw(value);
|
||||
}
|
||||
|
||||
template<Integral I>
|
||||
@ -278,9 +284,7 @@ public:
|
||||
}
|
||||
This& operator/=(This const& other)
|
||||
{
|
||||
// FIXME: See above
|
||||
m_value /= other.raw();
|
||||
m_value <<= precision;
|
||||
*this = *this / other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user