Difference between Qt 5.6.x and 5.7.x ; floating precision
-
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 thisIn 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
-
11.26has to be11.3. It's Ok.
There is no specific threshold. if you round the value11.25with one decimal with Qt 5.6, it was11.2. With Qt 5.7 it is11.3. So simply why this difference between both Qt versions?
Now if you know the reason why, do you know a way to round11.25to11.2with Qt 5.7 and above? (probably the answer is to add an epsilon...)Thanks again...
David -
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 -
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@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.
-
@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.
@kshegunov said in Difference between Qt 5.6.x and 5.7.x ; floating precision:
Thanks a lot to everyone.