mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:17:46 +00:00
AK: Fix FixedPoint to integral comparisons
Add tests to ensure that the fixed point numbers compare correctly to integrals
This commit is contained in:
parent
f5fd2f3857
commit
5d6e3441fe
2 changed files with 29 additions and 24 deletions
|
@ -261,42 +261,22 @@ public:
|
|||
template<Integral I>
|
||||
bool operator>(I other) const
|
||||
{
|
||||
if (m_value > 0)
|
||||
return (m_value >> precision) > other || (m_value >> precision == other && (m_value & radix_mask));
|
||||
if (other > 0)
|
||||
return false;
|
||||
|
||||
return (m_value >> precision) > other || !(m_value >> precision == other && (m_value & radix_mask));
|
||||
return !(*this <= other);
|
||||
}
|
||||
template<Integral I>
|
||||
bool operator>=(I other) const
|
||||
{
|
||||
if (m_value > 0)
|
||||
return (m_value >> precision) >= other || (m_value >> precision == other && (m_value & radix_mask));
|
||||
if (other > 0)
|
||||
return false;
|
||||
|
||||
return (m_value >> precision) >= other || !(m_value >> precision == other && (m_value & radix_mask));
|
||||
return !(*this < other);
|
||||
}
|
||||
template<Integral I>
|
||||
bool operator<(I other) const
|
||||
{
|
||||
if (m_value > 0)
|
||||
return (m_value >> precision) < other || !(m_value >> precision == other && (m_value & radix_mask));
|
||||
if (other > 0)
|
||||
return true;
|
||||
|
||||
return (m_value >> precision) < other || (m_value >> precision == other && (m_value & radix_mask));
|
||||
return (m_value >> precision) < other || m_value < (other << precision);
|
||||
}
|
||||
template<Integral I>
|
||||
bool operator<=(I other) const
|
||||
{
|
||||
if (m_value > 0)
|
||||
return (m_value >> precision) <= other || !(m_value >> precision == other && (m_value & radix_mask));
|
||||
if (other > 0)
|
||||
return true;
|
||||
|
||||
return (m_value >> precision) <= other || (m_value >> precision == other && (m_value & radix_mask));
|
||||
return *this < other || *this == other;
|
||||
}
|
||||
|
||||
// Casting from a float should be faster than casting to a float
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue