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

JSON (de)serializer doesn't consider the sign of double/float zero

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P3: Somewhat important
    • None
    • 6.7, dev
    • Core: Serialization
    • None
    • All

    Description

      The minimal example produces values that do not consider the sign bit:

      #include <QApplication>
      #include <QJsonDocument>
      #include <QJsonObject>
      
      #include <cmath>
      
      int main(int argc, char *argv[])
      {
          QJsonDocument doc = QJsonDocument::fromJson("{\"test\":-0}");
          QJsonObject obj = doc.object();
          auto d = obj.value("test").toDouble();
      
          // Expected to be "true"
          qDebug() << "Sign bit: " << std::signbit(d);
      
          d = -0;
          obj.insert("test", d);
          doc.setObject(obj);
      
          // Expected to be {"test":-0}
          qDebug() << "Resulting JSON: " << doc.toJson(QJsonDocument::Compact);
          return 0;
      }
      

      It's insignificant, but some implementations(the one is used in protobuf) consider and preserve the sign of zero when (de)serializing floating point values.

      Attachments

        Issue Links

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

          Activity

            People

              thiago Thiago Macieira
              semlanik Alexey Edelev
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes