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

QString::toFloat() fails on specific input

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.1
    • None
    • Windows

    Description

      Dear all,

      I am reading strings representing floats and converting them to float using QString()::toFloat().

      I noticed that on some inputs, this conversion fails (but toDouble() succeeds).

      Example:

      String: "-3.4028235e+038" (equivalent to 0xFFFF7FFF as LE-4byte float)

      Reading this with toFloat(&ok) fails (ok = false), using toDouble(&ok) works as expected.

       

      Interestingly, Qt can not parse its own output when using this float, converting it to QString using QString::number(f, 'g', 8) and trying to parse this QString again with toFloat().

       

      You can find a minimal example attached. Cases A and B show the conversion using toFloat() failing, cases C and D show the conversion of the same numbers succeed with toDouble().

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            phiber Philipp Berger
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes