[Development] Implementation of qFuzzyCompare and zero values

André Somers andre at familiesomers.nl
Thu Jul 25 07:34:19 CEST 2013


Op 25-7-2013 1:19, Thiago Macieira schreef:
> 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).
Would it be an option to _add_ a qFuzzyCompareMightBeNull or something 
like that then for cases like Juan describes where you don't know if one 
of the two values might be zero or not? There is no reason to change the 
behaviour of the current function (as said in the bug report: it may 
break or slow down other peoples code doing that), but that does not 
hold adding a new function *defined* to do this, right?

André

-- 
You like Qt?
I am looking for collegues to join me at i-Optics!




More information about the Development mailing list