C++ has a standard function isinf()? like isnan()?
If yes, it returns true in case of +inf and -inf also?

Recommended Answers

All 3 Replies

isnan() is from C99; and is not part of C++98. See http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.15
In C++0x, isnan() is part of TR1.

You could easily roll out isnan() and isinf() on your own, though:

#include <limits>

template< typename T > inline bool isnan( T value )
{ return value != value ; }

template< typename T > inline bool isinf( T value )
{
    return std::numeric_limits<T>::has_infinity &&
           value == std::numeric_limits<T>::infinity() ;
}

and I have to check -inf also, i think!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.