Review Request: KColorSpace::KHCY::KHCY(const & QColor) constructor floating point precision error

Benoit Jacob jacob.benoit.1 at gmail.com
Thu Jun 25 14:54:50 BST 2009


2009/6/25 Oswald Buddenhagen <ossi at kde.org>:
> On Thu, Jun 25, 2009 at 03:06:26PM +0200, Benoît Jacob wrote:
>> *** Can I use qFuzzyCompare to check if a number is close to zero?
>>
>> Never use qFuzzyCompare directly to check whether a number is
>> approximately zero. Doing
>>   qFuzzyCompare(p,0)
>> expands to
>>   return (qAbs(p) <= 0);
>> which is an exact comparison, it's basically the same as "p == 0" !
>>
> fwiw, qt master has qFuzzyIsNull() (or some similar name).

ah, good thing. But I can see that it doesn't take a "reference" parameter:

static inline bool qFuzzyIsNull(double d)
{
    return qAbs(d) <= 0.000000000001;
}

so it is suitable only in the special case that I describe at the end
of my email: when numbers that are negligible compared to 1, can be
considered negligible.

In a setting where one is dealing with numbers like 1e+10 already,
qFuzzyIsNull behaves like an exact comparison, which is no what's
wanted!

Yes in the constext of kcolorspaces.cpp it is what you want.

Benoit




More information about the kde-core-devel mailing list