By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,196 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,196 IT Pros & Developers. It's quick & easy.

testing for quiet not a number (QNAN)

P: n/a
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?
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Fri, 11 Jun 2004 23:38:30 +0100, Dylan <sp******@ontheball.com>
wrote:
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
Jul 22 '05 #2

P: n/a
On Sat, 12 Jun 2004 00:55:23 +0200, Dylan wrote:
On Fri, 11 Jun 2004 23:38:30 +0100, Dylan <sp******@ontheball.com>
wrote:
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
}


Don't do that!

man finite
man isnan
man isinf
less /usr/include/math.h: fpclassify, isfinite
http://www.delorie.com/gnu/docs/glib....html#SEC_Top:
chapter. 20

HTH, Darius.
Jul 22 '05 #3

P: n/a
In message <2j************@uni-berlin.de>, Darius.Moos AT esigma-systems
DOT de <pf*********@gmx.de> writes
On Sat, 12 Jun 2004 00:55:23 +0200, Dylan wrote:
On Fri, 11 Jun 2004 23:38:30 +0100, Dylan <sp******@ontheball.com>
wrote:
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
}


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.
http://www.delorie.com/gnu/docs/glib....html#SEC_Top:
chapter. 20


"The GNU C Library"

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

--
Richard Herring
Jul 22 '05 #4

P: n/a
On Tue, 15 Jun 2004 17:34:04 +0200, Richard Herring wrote:
On Fri, 11 Jun 2004 23:38:30 +0100, Dylan <sp******@ontheball.com>
wrote:
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
}
[...] Can you explain your point by reference to the C++ standard?


No ?
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.