From 14d9633f576429b29257ed43143abc6de3918e5d Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Mon, 30 Mar 2009 13:48:46 +0200 Subject: Adding note to the qFuzzyCompare doc Adding note about how comparing using 0.0 will fail, and an example on how to do it. Reviewed-by: David Boddie Reviewed-by: Geir Vattekar --- doc/src/snippets/code/src_corelib_global_qglobal.cpp | 8 ++++++++ src/corelib/global/qglobal.cpp | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/src/snippets/code/src_corelib_global_qglobal.cpp b/doc/src/snippets/code/src_corelib_global_qglobal.cpp index 72663e9..287181a 100644 --- a/doc/src/snippets/code/src_corelib_global_qglobal.cpp +++ b/doc/src/snippets/code/src_corelib_global_qglobal.cpp @@ -456,3 +456,11 @@ class MyClass : public QObject //! [45] QWidget w = QWidget(); //! [45] + +//! [46] + // Instead of comparing with 0.0 + qFuzzyCompare(0.0,1.0e-200); // This will return false + // Compare adding 1 to both values will fix the problem + qFuzzyCompare(1 + 0.0, 1 + 1.0e-200); // This will return true +//! [46] + diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 68c213e..69d0a53 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -2942,7 +2942,12 @@ bool QInternal::callFunction(InternalFunction func, void **args) Compares the floating point value \a p1 and \a p2 and returns \c true if they are considered equal, otherwise \c false. - + + Note that comparing values where either \a p1 or \a p2 is 0.0 will not work. + The solution to this is to compare against values greater than or equal to 1.0 + + \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 46 + The two numbers are compared in a relative way, where the exactness is stronger the smaller the numbers are. */ -- cgit v0.12