0.5 != 0.5000000000 ??? why ??

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

belkacem
Quite a regular
Quite a regular
Posts: 83
Joined: Fri Jan 07, 2011 13:55

0.5 != 0.5000000000 ??? why ??

Postby belkacem » Thu Jul 07, 2011 19:40

hello again!!

my problem this time is not programming problem ( i think it is Boolean one )

i create a tab button and tab control without any problem but when i resize it i do two value
0.5 and 0.500 , but imagine what happen
if i use 0.5 i get very small size in other hand i use 0.500 i get big size

and you know that in math 0.5 == 0.50000000000000 ( even how zero that i have )

any help !!

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: 0.5 != 0.5000000000 ??? why ??

Postby Jamarr » Mon Jul 11, 2011 18:42

This does not make any sense. Please provide the relevant code and screenshots.
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

User avatar
Mikademus
CEGUI MVP
CEGUI MVP
Posts: 130
Joined: Wed Mar 18, 2009 19:14

Re: 0.5 != 0.5000000000 ??? why ??

Postby Mikademus » Tue Jul 12, 2011 11:25

belkacem wrote:hello again!!
and you know that in math 0.5 == 0.50000000000000 ( even how zero that i have )


Unfortunately, for computer floating points this is not true. Basically, you never compare floats or doubles for equality (with ==), that will result in bugs, always compare the difference of two floats against a comparison criterion (usually called "epsilon"), as in

Code: Select all

const float epsilon = 0.000001f;
float a = 100.f;
float b = 50.f;
//wrong!: if (a - b == 50.f) doStuff();
if (a - b < epsilon) doStuff(); // correct


Note that this is beginner's programmers knowledge and you should already have been aware of it. It may or may not have anything to do with your widget sizing problem.

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: 0.5 != 0.5000000000 ??? why ??

Postby Kulik » Tue Jul 12, 2011 11:29

Mikademus wrote:

Code: Select all

if (a - b < epsilon) doStuff(); // correct



should be:

Code: Select all

if (std::fabs(a - b) < epsilon) doStuff(); // correct


And you can use std::numeric_limits<float>::epsilon() as epsilon.

Still, I think this could be a parsing problem, not necessarily a floating point precision problem.

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: 0.5 != 0.5000000000 ??? why ??

Postby Jamarr » Tue Jul 12, 2011 17:20

i create a tab button and tab control without any problem, but when i resize it i do two value 0.5 and 0.500, but imagine what happen: if i use 0.5 i get very small size, in other hand i use 0.500 i get big size.


I am pretty sure he is not talking about comparing two floats, despite the title of this thread. This is why I asked for more info ;)
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!


Return to “Help”

Who is online

Users browsing this forum: No registered users and 27 guests