[Interest] Is it a LGPLv3 infringement to copy paste qFuzzyCompare implementation

Ch'Gans chgans at gna.org
Fri Jul 22 05:00:45 CEST 2016


Hi there,

I've recently added a "bool FuzzyCompare(float f1, float f2)" function
to a proprietary software I'm currently paid to work on (this is plain
C++ project, it doesn't use the Qt framework at all).
Being a more-than-happy Qt user in my spare time I decided that I
would first checkout the qFuzzyCompare implementation since I consider
Qt developers as top-of-the-notch C++ wizards (no kidding and no
attempt to be nice with them).

I have added a comment to "my" implementation referring to the
implementation of "qFuzzyCompare" in Qt5 source code (along with [1]).
The 2 implementations look alike indeed (apart from using std::fabsf,
std::min, etc.. in place of qAbs, qMin, ...), since the fuzzy compare
is a well-known algorithm.
My reference to Qt5 was there to justify the use of the "magic
constant" 100000.f.

I was pointed out that there's a potential LGPLv3 license
infringement, although I understand where the FUD is coming from, I
think that it is OK to read LGPLv3 source code to get inspired as long
as you don't blindly copy/paste code (In my case i checked out quite a
few articles and forum threads before choosing the Qt way as the best
way to do it for my application).

So my question is actually very serious, in this particular case,
would this be considered as a LGPLv3 infringement of Qt5 to add this
to a piece of proprietary software:
   // Taken from Qt5 source code, see
http://doc.qt.io/qt-5/qtglobal.html#qFuzzyCompare-1 and
    // https://code.woboq.org/qt5/qtbase/src/corelib/global/qglobal.h.html#_ZL13qFuzzyCompareff
    // And for the insomniacs:
https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
    bool FuzzyCompare(float f1, float f2)
    {
        return (::fabsf(f1 - f2) * 100000.0f <= std::min(::fabsf(f1),
::fabsf(f2)));
    }

For comparison purpose, here is the Qt source code:
Q_DECL_CONSTEXPR static inline bool qFuzzyCompare(float p1, float p2)
{
  return (qAbs(p1 - p2) * 100000.f <= qMin(qAbs(p1), qAbs(p2)));
}

You can find many more implementations of this algorithm on
stack-overflow and other forums.

At the end, I proposed to change the comments to refer to wikipedia
instead of Qt5 source code and saying that 100000.0f is the right
value for epsilon.

I know this is a drop in an ocean (we're talking 1 line of C++), but i
think the question is indeed interesting. Thanks for shedding light on
this particular issue.

Chris


[1] https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/



More information about the Interest mailing list