Jump to content
  • Advertisement

Archived

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

Malone1234

Infinite or NaN in C++?

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

Does C++ have anything in the standard library similar to Java''s Double.isInfinite() function? Or can anybody point me to a library or function that will check whether a double floating point number is infinite or NaN?

Share this post


Link to post
Share on other sites
Advertisement
http://www.cis.nctu.edu.tw/chinese/doc/research/c++/C++FAQ-English/newbie.html#faq-29.15

that same thing should work for inf as well i think. at the route, i believe that a certain bit is flipped for NAN or inf numbers by the CPU. there's a way to check the same thing by just doing a bitwise & and a comparison check.

also look here:
http://gundog.lbl.gov/VS/doc/atomic_class_api_html/sparkmath_8h-source.html

-me

p.s. i'm finding all this information using this new tool called google

[edited by - Palidine on March 18, 2004 1:17:44 PM]

Share this post


Link to post
Share on other sites

#include <cmath>

bool foo(float f)
{
return std::isinf(f);
}


To check for NaN, use std::isnan().

[edited by - sbennett on March 18, 2004 2:15:34 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!