testing for quiet not a number (QNAN)

D

Dylan

I need to write logic that checks a variable (a float) and branches
when that variable is set to the representation of QNAN.

I thought the following would work, but it doesn't.

if (MyVariable == std::numeric_limits<float>::quiet_NaN())
{
//blah blah
}

Any ideas?
 
D

Dylan

I need to write logic that checks a variable (a float) and branches
when that variable is set to the representation of QNAN.

I thought the following would work, but it doesn't.

if (MyVariable == std::numeric_limits<float>::quiet_NaN())
{
//blah blah
}

Any ideas?


ah ha!

It's okay I found the answer. A NAN will test unequal to any value
even itself, so...

if (MyVariable != MyVariable)
{
//blah blah
}

works
 
R

Richard Herring

Darius.Moos AT esigma-systems said:
Don't do that!

man finite

The name specified is not recognized as an
internal or external command, operable program or batch file.
man isnan

The name specified is not recognized as an
internal or external command, operable program or batch file.
man isinf

The name specified is not recognized as an
internal or external command, operable program or batch file.
less /usr/include/math.h: fpclassify, isfinite

The name specified is not recognized as an
internal or external command, operable program or batch file.

"The GNU C Library"

Can you explain your point by reference to the C++ standard?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top