473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

testing for quiet not a number (QNAN)

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
4 10439
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Eduardo Biano | last post by:
Hi, I have a problem making conditional testing (if) of a form variable "ans01"(refer generated error). When the form variable is tested (if) by a called function (foo) the value of "ans01" is...
0
by: Jonathan Allen | last post by:
We have found that our method of testing does not match traditional text-book methodologies. I decided to write a short white paper on it so that I could get your opinions. Does anyone else use...
6
by: Lionel B | last post by:
Running VC++ 6 under Win2K on i386. I would like to assign a (compile-time) constant that resolves to a quiet NaN (of type double) I can assign a quiet NaN to a *variable* (of type const...
3
by: zorro | last post by:
Hello, If I have to test my code on different Netscape versions, can I download and run those versions on the same computer or will it create conflicts? And if I had to test only one version...
0
by: could ildg | last post by:
The paragraph is as below, I mark the word quiet with *** ***. ___________________________________ One problem with distributed applications is that if no data arrives over a long period of time,...
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
1
by: p.lavarre | last post by:
Looks like every run of doctest after the first is verbose: $ python2.5 quiet-once.py (0, 0) *** DocTestRunner.merge: '__main__' in both testers; summing outcomes. (0, 0) ***...
2
by: Greg Corradini | last post by:
Hello all, I'm running descriptive stats on mileages from a database (float numbers, about a million records). My sum returns 1.#QNAN, which I understand from searching this forum is an error. ...
24
by: David | last post by:
Hi list. What strategies do you use to ensure correctness of new code? Specifically, if you've just written 100 new lines of Python code, then: 1) How do you test the new code? 2) How do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.