Is the equal?

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

Recommended Posts

float f = 1.7e38f; float ff = f + 1.3e22f; if (f == ff) cout<<"ok!";//output ok!

Share on other sites
floating point types are not absolutely precise. They can only how so many significant figures. So in your cast is is like adding 10,000,000 + 1 = 10,000,001, except that since floats only have so many significant figures it rounds it back to 10,000,000. If you want something twice as precise use the double type instead. You will probably get better results. If that doesn't work, come back for fancier solutions.

Share on other sites
floats are very inaccurate.. :p You shouldn't trust them.. :p

Share on other sites
floats have around 24-bits of precision, doubles have around 53. f is about 10^16 times greater than ff. 10^16 is about 2^53... so even using a double is pushing it.

Share on other sites
You could try a long double.. Probably 64+ bits of precision (80 bits in total).. Still, never trust them to be accurate..

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 14
• 10
• 9
• 11
• Forum Statistics

• Total Topics
634096
• Total Posts
3015492
×