[Development] Should QVariant be doing fuzzy comparisons on doubles?
Thiago Macieira
thiago.macieira at intel.com
Wed Sep 21 06:15:09 CEST 2016
On quarta-feira, 21 de setembro de 2016 03:56:31 PDT Kevin Kofler wrote:
> Thiago Macieira wrote:
> > And I will reject any patch that adds more complexity in qFuzzyCompare for
> > a 0.01% corner-case. Instead, we should document that it only works for
> > finite numbers far enough away from zero. If your number can be infinite
> > or NaN or zero, you have to find something else.
>
> This is just ridiculous, the code would be fixing a clear bug, and avoid
> having to very dangerously change the behavior of QVariant.
The clear bug is in QVariant and my original patch fixed qvariant.cpp
numericCompare function. It's ok to call fpclassify() there, since QVariant
comparison is not expected to be really fast. Besides, it's out-of-line code.
However, I will oppose adding fpclassify() or isinf() to qFuzzyCompare. That
function has existed for 10 years (or more) and this is this is the first we
ever discuss it having a problem. The bug report isn't even about
qFuzzyCompare, so as far as I know, no user has ever complained about it not
working for infinities.
I do remember a discussion some 8 or 9 years ago about using qFuzzyCompare to
compare to zero. That's why qFuzzyIsNull exists. Which also means that
QVariant comparisons to exact-zero or when the numbers are close to zero
aren't fuzzy.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Development
mailing list