Archived

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

Malone1234

Infinite or NaN in C++?

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
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