Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Difference between Qt 5.6.x and 5.7.x ; floating precision
I try to understand why this :
float b = 11.25; qDebug() << QString::number(b, 'f', 1);
- 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 this
In 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.
VRonin last edited by
Hi, would you want
11.26to still be
11.3? basically what is the threshold for
11.26has to be
11.3. It's Ok.
There is no specific threshold. if you round the value
11.25with one decimal with Qt 5.6, it was
11.2. With Qt 5.7 it is
11.3. So simply why this difference between both Qt versions?
Now if you know the reason why, do you know a way to round
11.2with Qt 5.7 and above? (probably the answer is to add an epsilon...)
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
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.