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

qRound64 does not round correctly for very large integers

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.0
    • None

    Description

      The following code fails with the message below:

      qlonglong i64 = (1ll << 52) + 1;
      double d = i64;
      QVERIFY(d == i64);
      QCOMPARE(qRound64(d), i64);

       

      FAIL! Compared values are not the same
      Actual (qRound64(d)): 4503599627370498
      Expected (i64) : 4503599627370497

       

      The integer value above has an exact representation within a double. It is the qRound64 method, which adds 0.5 to the integral value and thus introduces loss of precision in this step.

       

      I didn't check if qRound is affected as well.

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            fkaelberer Felix Kälberer
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes