[Development] Implementation of qFuzzyCompare and zero values

Thiago Macieira thiago.macieira at intel.com
Thu Jul 25 01:19:50 CEST 2013

On quarta-feira, 24 de julho de 2013 20:32:26, Juan Navarro wrote:
> 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.

You have to somehow tell qFuzzyCompare about the magnitude of your comparison. 
An error of 1000000 is acceptable when your numbers are in the order of 1e12.

> 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.

Can't do and won't do that. qFuzzyCompare is meant for non-zero numbers. We 
don't want to add the overhead of zero comparisons when the numbers in 
question can't be null.

I've now just closed the bug report as "out of scope" (not a bug).

> Could anyone add a bit more on this subject?

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130724/b4a447cd/attachment.sig>

More information about the Development mailing list