From 6a3a28236c6a0c34d37a614ca4e68ccd136d90e2 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 27 Aug 2024 17:05:14 +0200 Subject: [PATCH] qFuzzy(Compare|IsNull)(): mark as noexcept These all cannot fail, so can and should be noexcept. Most were already. Found in API-review. [ChangeLog][QtCore/QtGui] All qFuzzyCompare() and qFuzzyIsNull() overloads are now noexcept. Pick-to: 6.8 Change-Id: I67a2981ea4af9be0370becf84103822fd766ab5e Reviewed-by: Ivan Solovev --- src/corelib/global/qnumeric.h | 8 ++++---- src/gui/math3d/qmatrix4x4.cpp | 2 +- src/gui/math3d/qmatrix4x4.h | 2 +- src/gui/painting/qtransform.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/corelib/global/qnumeric.h b/src/corelib/global/qnumeric.h index 2238c13da09..521cf98b09d 100644 --- a/src/corelib/global/qnumeric.h +++ b/src/corelib/global/qnumeric.h @@ -366,22 +366,22 @@ template constexpr inline const T &min(const T &a, const T &b) { return (a < b) ? a : b; } } -[[nodiscard]] constexpr bool qFuzzyCompare(double p1, double p2) +[[nodiscard]] constexpr bool qFuzzyCompare(double p1, double p2) noexcept { return (qAbs(p1 - p2) * 1000000000000. <= QtPrivate::min(qAbs(p1), qAbs(p2))); } -[[nodiscard]] constexpr bool qFuzzyCompare(float p1, float p2) +[[nodiscard]] constexpr bool qFuzzyCompare(float p1, float p2) noexcept { return (qAbs(p1 - p2) * 100000.f <= QtPrivate::min(qAbs(p1), qAbs(p2))); } -[[nodiscard]] constexpr bool qFuzzyIsNull(double d) +[[nodiscard]] constexpr bool qFuzzyIsNull(double d) noexcept { return qAbs(d) <= 0.000000000001; } -[[nodiscard]] constexpr bool qFuzzyIsNull(float f) +[[nodiscard]] constexpr bool qFuzzyIsNull(float f) noexcept { return qAbs(f) <= 0.00001f; } diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index d04a5025195..013908a714f 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -735,7 +735,7 @@ QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor) Returns \c true if \a m1 and \a m2 are equal, allowing for a small fuzziness factor for floating-point comparisons; false otherwise. */ -bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2) +bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2) noexcept { return qFuzzyCompare(m1.m[0][0], m2.m[0][0]) && qFuzzyCompare(m1.m[0][1], m2.m[0][1]) && diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h index f8e5bc43147..80ba62ca36f 100644 --- a/src/gui/math3d/qmatrix4x4.h +++ b/src/gui/math3d/qmatrix4x4.h @@ -93,7 +93,7 @@ public: friend QMatrix4x4 operator*(const QMatrix4x4& matrix, float factor); friend Q_GUI_EXPORT QMatrix4x4 operator/(const QMatrix4x4& matrix, float divisor); - friend Q_GUI_EXPORT bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2); + friend Q_GUI_EXPORT bool qFuzzyCompare(const QMatrix4x4& m1, const QMatrix4x4& m2) noexcept; #ifndef QT_NO_VECTOR3D void scale(const QVector3D& vector); diff --git a/src/gui/painting/qtransform.h b/src/gui/painting/qtransform.h index 3a858383373..50f065957ee 100644 --- a/src/gui/painting/qtransform.h +++ b/src/gui/painting/qtransform.h @@ -304,7 +304,7 @@ inline QTransform &QTransform::operator-=(qreal num) QT_WARNING_POP -inline bool qFuzzyCompare(const QTransform& t1, const QTransform& t2) +inline bool qFuzzyCompare(const QTransform& t1, const QTransform& t2) noexcept { return qFuzzyCompare(t1.m11(), t2.m11()) && qFuzzyCompare(t1.m12(), t2.m12())