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

qfloat16 compares all integral values outside its range equal to infinity

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.5, 6.6, dev
    • Core: Other
    • None
    • 3
    • Foundation PM Prioritized, Foundations Sprint 97, Foundations Sprint 98, Foundations Sprint 99, Foundation Sprint 100, Foundation Sprint 101, Foundations Sprint 102, Foundation Sprint 103, Foundation Sprint 104, Foundation Sprint 105, Foundation Sprint 106

    Description

      As pointed out by Eddy in the comments to https://codereview.qt-project.org/c/qt/qtbase/+/481410/14, qfloat16 implements relational operators in such way, that all integral values outside of its range are equal to qfloat16's infinity.

      The same problem exists for qfloat16 vs qfloat16 comparison.

      This is not an expected behavior, if we compare it with built-in types. Consider the following example:

      const float inf = std::numeric_limits<float>::infinity();
      const float out_of_qf16_range = 13e5f;
      
      const qfloat16 qf16_inf = qfloat16(inf);
      Q_ASSERT(qf16_inf.isInf());
      
      // built-in types
      Q_ASSERT(inf != out_of_qf16_range); // float vs float
      Q_ASSERT(inf != int(out_of_qf16_range)); // float vs int
      // qfloat16
      Q_ASSERT(qf16_inf != out_of_qf16_range); // OK!
      Q_ASSERT(qf16_inf != int(out_of_qf16_range)); // qf16 vs int - FAIL!
      Q_ASSERT(qf16_inf != qfloat16(out_of_qf16_range)); // qf16 vs qf16 -  FAIL!
      

      This is discovered while working on C++20 comparison story, but this is a pre-existing problem.

      Comparison with FP types works as expected.

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-118193
          # Subject Branch Project Status CR V

          Activity

            People

              mmutz Marc Mutz
              ivan.solovev Ivan Solovev
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change