Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-16819

Weird implementation of qFuzzyCompare. qFuzzyCompare and 0.0.

    XMLWordPrintable

Details

    Description

      Current implementation of qFuzzyCompare for floats and doubles can fail if p1 or p2 are equal to 0.0. That is documented, but I don't see any reason to do that. Why just not to handle it?

      Current implementation:

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

      Always working implementation:

      static inline bool qFuzzyCompare(double p1, double p2)
      {
          if( p1 != 0.0 && p2 != 0.0) {
              return (qAbs(p1 - p2) <= 0.000000000001 * qMin(qAbs(p1), qAbs(p2)));
          } else {
              return (qFuzzyCompare(p1+1.0, p2+1.0));
          }
      }
      

      Standart implementation can result in strange errors, isn't it?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            lapidarno Denis Pesotsky
            Votes:
            2 Vote for this issue
            Watchers:
            11 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes