Jump to content
  • Advertisement
Sign in to follow this  
WindScar

[C++] math.h sin(M_PI) problem.

This topic is 3091 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

Advertisement
M_PI is not exactly pi, because floating-point values cannot represent pi exactly. Therefore, the sine of M_PI is not 0.

Share this post


Link to post
Share on other sites
Quote:
Original post by WindScar
It's returning a weird number that's not zero. What's wrong?
Probably just a precision issue. Can you post the number that you're getting?

[Too slow...]

Share this post


Link to post
Share on other sites
Link favorited for future reading. The number I'm getting is 6.12303e-17. I suppose it's very close to 0 but I don't know how to read it.

Share this post


Link to post
Share on other sites
It seems a bit weird to have such a small number in my console instead of 0, but I suppose that's too small to be a problem. Thank you.

Share this post


Link to post
Share on other sites
Quote:
Original post by WindScar
It seems a bit weird to have such a small number in my console instead of 0, but I suppose that's too small to be a problem. Thank you.


Well, it's too small to be a problem unless you're doing things like testing thingThatShouldBeZero == 0 and getting strange bugs as a result (in case it's not clear, you should test for thingThatShouldBeZero < epsilon). Floating point computation has lots of gotchas that are well worth learning about. If you're just worried about pretty-printing, use setprecision to cut it off at a sensible point.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!