Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. [QSpin boxes and strange values]
Forum Updated to NodeBB v4.3 + New Features

[QSpin boxes and strange values]

Scheduled Pinned Locked Moved Unsolved Qt 6
4 Posts 2 Posters 443 Views
  • 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.
  • A Offline
    A Offline
    appdev
    wrote on last edited by
    #1

    Hello guys, I hope you're all doing well.

    So I've created an application that rotates an object using quaternion. [It's an animation of the rotation]
    Quaternion values are extracted from a certain csv file.
    So each time the object rotates, the value of each element of the quaternion ( w, x, y and z) is displayed in the Spin boxes of the UI.
    there are four spin boxes; I fixed the max number of decimals to 9, because some elements of the quaternion have 9 numbers after the comma.

    Other quaternion values have less than 9 numbers after the comma for example
    w=0.7236
    in the QSpin box, I get w=0.723698556.
    98556 is added automatically and I don't even understand why that happens.

    Any idea on what's really happening or on how I can fix that ?

    Any help would be really appreciated.

    Thank you all.

    JonBJ 1 Reply Last reply
    0
    • A appdev

      Hello guys, I hope you're all doing well.

      So I've created an application that rotates an object using quaternion. [It's an animation of the rotation]
      Quaternion values are extracted from a certain csv file.
      So each time the object rotates, the value of each element of the quaternion ( w, x, y and z) is displayed in the Spin boxes of the UI.
      there are four spin boxes; I fixed the max number of decimals to 9, because some elements of the quaternion have 9 numbers after the comma.

      Other quaternion values have less than 9 numbers after the comma for example
      w=0.7236
      in the QSpin box, I get w=0.723698556.
      98556 is added automatically and I don't even understand why that happens.

      Any idea on what's really happening or on how I can fix that ?

      Any help would be really appreciated.

      Thank you all.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @appdev
      It's all to do with the accuracy of double values. Unlike integers, computers cannot represent floating point number with 100% accuracy, and far from all real numbers can be handled, only a subset.

      Let's start with: what QSpin box are you using. I doubt it's a QSpinBox at all, is it a QDoubleSpinBox?

      w=0.7236
      in the QSpin box, I get w=0.723698556.

      Are you sure these are the actual numbers? Can you look closely again. I would have expected either one (bit not both) of

      • w=0.7237
      • w=0.723598556
      1 Reply Last reply
      1
      • A Offline
        A Offline
        appdev
        wrote on last edited by
        #3

        @JonB First of all, thank you for the reply.

        Yes it's a QDoubleSpinBox.
        okay for example:
        the first quaternion values extracted from the csv file are as follows:
        w=-0.169757
        x=-0.00949828
        y=-0.550083
        z=0.817619

        These are not the exact same values displayed in the Spin boxes.
        w=-0.1697576934
        x=-0.00949828277
        y=-0.550082743
        z=0.817619324

        The values in dark grey are added automatically, I don't even know how and why.
        Why aren't they equal to 0 ?

        In design mode I fixed the number of decimals of each spin box to 9, meaning there are 9 numbers after the comma and before representing any orientation I have:
        w=1.000000000
        x=0.000000000
        y=0.000000000
        z=0.000000000

        JonBJ 1 Reply Last reply
        0
        • A appdev

          @JonB First of all, thank you for the reply.

          Yes it's a QDoubleSpinBox.
          okay for example:
          the first quaternion values extracted from the csv file are as follows:
          w=-0.169757
          x=-0.00949828
          y=-0.550083
          z=0.817619

          These are not the exact same values displayed in the Spin boxes.
          w=-0.1697576934
          x=-0.00949828277
          y=-0.550082743
          z=0.817619324

          The values in dark grey are added automatically, I don't even know how and why.
          Why aren't they equal to 0 ?

          In design mode I fixed the number of decimals of each spin box to 9, meaning there are 9 numbers after the comma and before representing any orientation I have:
          w=1.000000000
          x=0.000000000
          y=0.000000000
          z=0.000000000

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @appdev said in [QSpin boxes and strange values]:

          Why aren't they equal to 0 ?

          Because as I said not all values are exactly representable in a computer double. In fact, to be exact the number which are exactly representable is an infinitely small subset of real numbers!

          Forget about spin boxes for now.

          • Show your code which reads the numbers from CSV file.

          • Use something like QString QString::number(double n, char format = 'g', int precision = 6) to convert your numbers to strings for displaying/debugging purposes. See what happens if you play with the precision parameter to increase/decrease how many digits are output.

          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