Jump to content
  • Advertisement
Sign in to follow this  
Matthew Doucette

make tan(pi/2) = infinity in C?

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

Can you make "tan()" crash, by passing it pi/2 (which results in infinity)? I tested it out, with float and double, and I cannot pass it exactly pi/2, so it does not crash. I've also tried pi/2+pi, pi/2+2pi, etc. Is it possible?

Share this post


Link to post
Share on other sites
Advertisement
tan(pi/2) will not crash, "infinity" is a valid floating-point value.

Share this post


Link to post
Share on other sites
Thank you. I couldn't see tan() crashing so it obviously must pass back "INF" if tan(pi/2), or similar infinity producing values, is performed.

In reality it is hard to test because it is hard to pass tan() an exact value to have it return infinity.

Share this post


Link to post
Share on other sites
hehe, yeah "hard" is one way of putting it [smile] pi/2 is an irrational number, so you cannot represent it exactly using standard floats or doubles. As a result you may not be able to actually get tan(), etc. to return an INF.

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!