[Development] Implementation of qFuzzyCompare and zero values

Saether Jan-Arve Jan-Arve.Saether at digia.com
Thu Jul 25 12:05:50 CEST 2013


Instead of qFuzzyCompareMightBeNull, why can't we have a function that returns the number of representable numbers between two floats?

boost has a similar function, math::float_distance(a, b)

Qt style API could then be something like:
unsigned qFloatDistance(float a, float b);

You can then compare two floats like this:
if (qFloatDistance(a,b) < 4) {
    // precise enough
}

This could be implemented the same way as explained in the link Samuel gave.
(http://www.cygnus-software.com/papers/comparingfloats/Comparing%20floating%20point%20numbers.htm#_Toc135149455)

Jan Arve


From: development-bounces+jan-arve.saether=digia.com at qt-project.org [mailto:development-bounces+jan-arve.saether=digia.com at qt-project.org] On Behalf Of Laszlo Papp
Sent: 25. juli 2013 09:47
To: André Somers
Cc: development at qt-project.org
Subject: Re: [Development] Implementation of qFuzzyCompare and zero values

On Thu, Jul 25, 2013 at 6:34 AM, André Somers <andre at familiesomers.nl<mailto:andre at familiesomers.nl>> wrote:
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?

That was also my thought after reading Thiago's email. It would not bloat the library after all as it is just a small function. I think the bugreport should be reopened accordingly, and then fixed unless there are good reasons against it.

Laszlo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20130725/61672f7a/attachment.html>


More information about the Development mailing list