Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how to check a double is inf or NaN?

Reply
Thread Tools

how to check a double is inf or NaN?

 
 
zl2k
Guest
Posts: n/a
 
      01-17-2007

Greg wrote:
> Ondra Holub wrote:
> > Greg napsal:
> > > Ondra Holub wrote:
> > > > Ondra Holub napsal:
> > > > > zl2k napsal:
> > > > > > hi,
> > > > > > Can someone let me know the command to check if a value is inf or NaN
> > > > > > in c++? I am using gcc in linux. Thanks for help.
> > > > > > zl2k
> > > > >
> > > > > // requires #include <limits>
> > > > > template<typename T>
> > > > > inline bool isinf(T value)
> > > > > {
> > > > > return std::numeric_limits<T>::has_infinity() &&
> > > > > value == std::numeric_limits<T>::infinity();
> > > > > }
> > >
> > > This implementation of isinf() incorrectly returns false when value is
> > > equal to negative infinity.

> >
> > Question was, how to check for infinity (which I understand positive
> > infinity as 1 is understand +1), not how to check for positive or
> > negative infinity.

>
> The standard routine, isinf() in <math.h> tests for whether its
> argument has an infinite value. Therefore isinf() returns true when
> called with either positive or negative infinity, because both are
> infinite values.
>
> Implementing another isinf() function that performs a similar, but
> different test, would just cause confusion - at best. A programmer
> would have to make sure which isinf() is being called in a particular
> fil - just to know what its return value means.
>
> Greg


Thanks for all the comments, very helpful.

zl2k

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
checking double for Inf or NaN - how? =?ISO-8859-1?Q?Martin_J=F8rgensen?= C Programming 55 06-03-2006 10:00 PM
Value of INF (double) Rob.Meyer1@gmail.com C++ 6 09-28-2005 01:38 AM
cannot convert parameter from 'double (double)' to 'double (__cdecl *)(double)' error Sydex C++ 12 02-17-2005 06:30 PM
How to force Tomcat to reload WEB-INF/lib and WEB-INF/classes ??? Hans Java 3 05-16-2004 04:57 PM



Advertisments