Archived

This topic is now archived and is closed to further replies.

Comparing floats

This topic is 5113 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im having trobule comparing 2 floats val and val1 are two floats, when i output them both to the console they have the values 2.2374 and 2.2374 (identical) but when being compared with an assert assert( val < (val2 + std::numeric_limits::epsilon()) && val > (val1 - std::numeric_limits::epsilon())); the assert fails.. how can i compare the values them?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The reason they appear the same from the console is because of the fact that it''s only displaying so many significant digits...

Share this post


Link to post
Share on other sites
yea, increased the precision of the console and the numbers are

2.237401 and 2.237402

the epsilon was 1.192092896e-07F, so it wasnt picking up the inaccuacy

thanks for the help

Share this post


Link to post
Share on other sites