[Development] Implementation of qFuzzyCompare and zero values

Juan Navarro oneorjuan at gmail.com
Wed Jul 24 20:32:26 CEST 2013


Hello all,

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)) ||
qFuzzyCompare((a), (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...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130724/69739b4a/attachment.html>


More information about the Development mailing list