[Development] Implementation of qFuzzyCompare and zero values
oneorjuan at gmail.com
Wed Jul 24 20:32:26 CEST 2013
I’m using qFuzzyCompare(a, b) in order to handle all floating point
comparisons, but it has severe limitations when a or b may be zero.
Somewhere in the docs it is recommended to add +1 to the values, but this
is not a really useful suggestion because some of the values might be -1.0,
resulting in 0.0 after the addition.
So in each file which needs to perform floating point comparisons, I always
end up using this or something similar to this macro:
#include <QtGlobal> // qMax, qMin, qFuzzyCompare
#define qFuzzyCompare(a, b) (qFuzzyIsNull(a) && qFuzzyIsNull(b)) ||
But instead of ad-hoc workarounds, IMHO this caveat should be fixed
straight in the implementation of the qFuzzyCompare() function. A really
old bug report already exists: QTBUG-16819 [bugreports.qt-project.org] it
is open but it seems that discussion ended on 2011 for some reason.
Could anyone add a bit more on this subject?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Development