QFixed: stream-line relational operators

- make them hidden friends
- take lhs and rhs each by value
- noexcept
- remove useless mixed relational operators with int: Every fix op i
  is now compiled as fix op QFixed(i) with no loss in performance.

Pick-to: 6.4
Change-Id: If4d0a43fd964547de59fed4ba2cdfea0cf176809
Reviewed-by: Lars Knoll <lars.knoll@gmail.com>
This commit is contained in:
Marc Mutz 2022-07-07 16:26:38 +02:00
parent 9b92f59940
commit 44653cdf4c

View File

@ -58,12 +58,17 @@ public:
inline QFixed &operator-=(const QFixed &other) { val -= other.val; return *this; }
constexpr inline QFixed operator-() const { return fromFixed(-val); }
constexpr inline bool operator==(const QFixed &other) const { return val == other.val; }
constexpr inline bool operator!=(const QFixed &other) const { return val != other.val; }
constexpr inline bool operator<(const QFixed &other) const { return val < other.val; }
constexpr inline bool operator>(const QFixed &other) const { return val > other.val; }
constexpr inline bool operator<=(const QFixed &other) const { return val <= other.val; }
constexpr inline bool operator>=(const QFixed &other) const { return val >= other.val; }
#define REL_OP(op) \
friend constexpr bool operator op(QFixed lhs, QFixed rhs) noexcept \
{ return lhs.val op rhs.val; }
REL_OP(==)
REL_OP(!=)
REL_OP(< )
REL_OP(> )
REL_OP(<=)
REL_OP(>=)
#undef REL_OP
constexpr inline bool operator!() const { return !val; }
inline QFixed &operator/=(int x) { val /= x; return *this; }
@ -130,19 +135,6 @@ constexpr inline QFixed operator+(uint i, const QFixed &d) { return d+i; }
constexpr inline QFixed operator-(uint i, const QFixed &d) { return -(d-i); }
// constexpr inline QFixed operator*(qreal d, const QFixed &d2) { return d2*d; }
constexpr inline bool operator==(const QFixed &f, int i) { return f.value() == i * 64; }
constexpr inline bool operator==(int i, const QFixed &f) { return f.value() == i * 64; }
constexpr inline bool operator!=(const QFixed &f, int i) { return f.value() != i * 64; }
constexpr inline bool operator!=(int i, const QFixed &f) { return f.value() != i * 64; }
constexpr inline bool operator<=(const QFixed &f, int i) { return f.value() <= i * 64; }
constexpr inline bool operator<=(int i, const QFixed &f) { return i * 64 <= f.value(); }
constexpr inline bool operator>=(const QFixed &f, int i) { return f.value() >= i * 64; }
constexpr inline bool operator>=(int i, const QFixed &f) { return i * 64 >= f.value(); }
constexpr inline bool operator<(const QFixed &f, int i) { return f.value() < i * 64; }
constexpr inline bool operator<(int i, const QFixed &f) { return i * 64 < f.value(); }
constexpr inline bool operator>(const QFixed &f, int i) { return f.value() > i * 64; }
constexpr inline bool operator>(int i, const QFixed &f) { return i * 64 > f.value(); }
#ifndef QT_NO_DEBUG_STREAM
inline QDebug &operator<<(QDebug &dbg, const QFixed &f)
{ return dbg << f.toReal(); }