qt - Using float or double for own QML classes -
i've created components , helper methods using c++ , qt used in qml gui. of methods calculate gui elements (size, transformations, scene graph items creation). target arm 32 bit using opengl / eglfs render output.
opengl using float
, qml using real
(defined double
).
what should use in c++ do not lose precision?
if use qreal
(double
) shouldn't lose precision. if git grep float
in qtbase.git
, can find out bit more:
dist/changes-5.2.0-**************************************************************************** dist/changes-5.2.0-* important behavior changes * dist/changes-5.2.0-**************************************************************************** dist/changes-5.2.0- dist/changes-5.2.0- - qt compiled qreal typedef'ed double on dist/changes-5.2.0: platforms. qreal float on arm chipsets before. guarantees more dist/changes-5.2.0- consistent behavior between platforms qt supports, binary dist/changes-5.2.0- incompatible qt 5.1 on arm. old behavior can restored dist/changes-5.2.0: passing -qreal float configure.
it's interesting note within qt, there large pieces of code have switched using float:
commit 51d40d7e9bdfc63c5109aef5b732aa2ba10f985a author: sean harmer <sean.harmer@kdab.com> date: mon aug 20 20:55:40 2012 +0100 make gui/math3d classes use float rather qreal corrects mismatch between using floats internal storage , qreal in api of qvector*d leads lots of implicit casts between double , float. change stops users being surprised loss of precision when using these classes on desktop platforms , removes need private constructors taking dummy int final argument. qmatrix4x4 , qquaternion classes have been changed use float internal storage since these meant used in conjunction qvector*d classes. prevent unexpected loss of precision , improve performance. on-disk format has been changed double float thereby reducing storage required when streaming vectors , matrices. potentially large saving when working complex 3d meshes etc. has significant performance improvement when passing matrices qopenglshaderprogram (and qglshaderprogram) no longer have iterate , convert data floats. operation needed many times per frame. change opens door further optimisations of these classes implemented using simd intrinsics.
as says, avoid surprise loss of precision functions took qreal
(double
) stored data float
. if use qreal
everywhere in own code, won't have problem.
the other reason performance. can't comment on that, i'd it's more important qt optimise such things most users of qt.
Comments
Post a Comment