c++ - qreal equality fails in release, but works in debug (and cast to float also works) -
in code, have large number of checks equality...
for example:
int main(int argc, char *argv[]) { qapplication a(argc, argv); qgraphicslineitem* x = new qgraphicslineitem(50, 50, -50, -50); qgraphicsview view(new qgraphicsscene(-200, -150, 400, 300) ); view.scene()->additem(x); view.show(); bool sameline = true; qlinef line1 = x->line(); qreal _length = line1.length(); foreach(qgraphicsitem* item, view.scene()->selecteditems()) { qgraphicslineitem *item2 = dynamic_cast<qgraphicslineitem*>(item); if(item2->line().length() != _length ) sameline = false; } qdebug("same line: %d", sameline); }
it seems work... in debug. when tested in release, fails ?
assume single selected item, item1
, item2
same, regardless of precision, above lengths should equal....
in debug, have not been able see fail... yet in release, fails !
the functions above (length()
) return qreal
the work-arounds see be
- implement own check equality, limits precision, or
- cast qreal
values float
.
illogical (and lot of work, have check lots of potential places).
can please explain why happening , how best go around problem ?
you should compare floating point values example qfuzzycompare
if use qt
. should never compare 2 floating point variables using ==
.
Comments
Post a Comment