Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Difference between Qt 5.6.x and 5.7.x ; floating precision
Forum Updated to NodeBB v4.3 + New Features

Difference between Qt 5.6.x and 5.7.x ; floating precision

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 832 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Desch
    wrote on last edited by
    #1

    Hi everyone,
    I try to understand why this :

    float b = 11.25;
    qDebug() << QString::number(b, 'f', 1);
    

    gives :

    • In Qt 5.6.x: 11.2
    • In Qt 5.7.x (and above ) : 11.3

    For testing I'm using Visual Studio 2013.

    It might be this reason, but not sure :
    Added the ability to convert a floating point to its shortest, exact string form, without having to pre-calculate how many digits that is; QVariant uses this

    In order to evaluate the impact of this change on my project, is it possible to go back to 11.2 (using a specific flag, a function or linking to other libraries) ?

    Thanks a lot for your help and merry Christmas to all of you.

    David

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Hi, would you want 11.26 to still be 11.2 or go 11.3? basically what is the threshold for 11.2 to become 11.3?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • D Offline
        D Offline
        Desch
        wrote on last edited by
        #3

        11.26 has to be 11.3. It's Ok.
        There is no specific threshold. if you round the value 11.25 with one decimal with Qt 5.6, it was 11.2. With Qt 5.7 it is 11.3. So simply why this difference between both Qt versions?
        Now if you know the reason why, do you know a way to round 11.25 to 11.2 with Qt 5.7 and above? (probably the answer is to add an epsilon...)

        Thanks again...
        David

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by Christian Ehrlicher
          #4

          Qt5.7 and above is using libdouble-conversion which could lead to a difference here. And since 11.25f can be converted to 11.2499999d there was maybe an error in the old implementation.
          This is also discussed here: https://bugreports.qt.io/browse/QTBUG-44039

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          kshegunovK 1 Reply Last reply
          5
          • Christian EhrlicherC Christian Ehrlicher

            Qt5.7 and above is using libdouble-conversion which could lead to a difference here. And since 11.25f can be converted to 11.2499999d there was maybe an error in the old implementation.
            This is also discussed here: https://bugreports.qt.io/browse/QTBUG-44039

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            @Christian-Ehrlicher said in Difference between Qt 5.6.x and 5.7.x ; floating precision:

            And since 11.25f can be converted to 11.2499999d

            11.25 is representable exactly in IEEE754. If it was rounded down then it's definitely a bug.

            Read and abide by the Qt Code of Conduct

            D 1 Reply Last reply
            3
            • kshegunovK kshegunov

              @Christian-Ehrlicher said in Difference between Qt 5.6.x and 5.7.x ; floating precision:

              And since 11.25f can be converted to 11.2499999d

              11.25 is representable exactly in IEEE754. If it was rounded down then it's definitely a bug.

              D Offline
              D Offline
              Desch
              wrote on last edited by
              #6

              @kshegunov said in Difference between Qt 5.6.x and 5.7.x ; floating precision:
              Thanks a lot to everyone.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved