[Qt-interest] strange qFuzzyCompare implementation

Peter Radagast istari-radagast at mail.ru
Sun Apr 12 16:51:09 CEST 2009


Hello!
I think all of us got used to high quality of the Qt design and implementation. And I was very disappointed, when I saw the qFuzzyCompare implementation:

static inline bool qFuzzyCompare(double p1, double p2)
{
    return (qAbs(p1 - p2) <= 0.000000000001 * qMin(qAbs(p1), qAbs(p2)));
}

static inline bool qFuzzyCompare(float p1, float p2)
{
    return (qAbs(p1 - p2) <= 0.00001f * qMin(qAbs(p1), qAbs(p2)));
}

Do you consider these hard-coded numbers etc effective, precise and portable?
I supposed to see smth like:
static inline bool qFuzzyCompare(double p1, double p2)
{
    return (qAbs(p1 - p2) <= std::numeric_limits::epsilon<double>());
}
At least it could be #ifndef'ed QT_NO_STL or smth like that and have current body with 0.0<many zeros>1 for users who wanna be independent from STL.
So, I'll be very thankful if someone could explain the advantages and motivation behind the current implementation?..





More information about the Qt-interest-old mailing list