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. Precision of QJson parser/integer limits

Precision of QJson parser/integer limits

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 972 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.
  • F Offline
    F Offline
    fharjes
    wrote on 18 Feb 2015, 09:02 last edited by
    #1

    I have a problem regarding the precision of the QJsonParser. A few days ago, I was able to solve the task of parsing a json from a file in general (with help of the forum in this thread:http://qt-project.org/forums/viewthread/52980/).

    Now, I noticed that some conversions during the parsing process do not have the required precision. For example, a 64-bit integer from the file, such as "73847942565529089", is stored as the QJsonValue "73847942565529088". The integer "73847942566053377" results in "73847942566053376". There are more similar cases, where the last digit is not correct. How can I ensure a correct conversion/parsing for such values?

    It seems that the integer limits for IEEE 754 double precision data are the problem here. Is there any way to bypass this problem (to get the "original" string during the parsing, etc.)?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JKSH
      Moderators
      wrote on 23 Feb 2015, 01:42 last edited by
      #2

      Hi,

      You're right, the issue stems from the original JSON specification which represents all numbers as double-precision floating point numbers (or at least, it was originally interpreted this way). There's currently no way to parse 64-bit integers using QJson, but there's a "recent discussion":http://comments.gmane.org/gmane.comp.lib.qt.devel/20202 among Qt engineers on how to work around this.

      In the meantime, you could store your numbers as strings, and then manually convert them to integers.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fharjes
        wrote on 24 Feb 2015, 08:04 last edited by
        #3

        Thank you for the information! In the meantime, I could bypass the problem by splitting the related values into blocks of 32bits each (within the json).

        1 Reply Last reply
        0

        1/3

        18 Feb 2015, 09:02

        • Login

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