Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate a NaN

I want to use a NaN to cause breaks in a cwgraph plot. How can I generate such a number in VC 6.0
0 Kudos
Message 1 of 4
(6,040 Views)
Paul,
one way to do it is with the C++ Standard Library's numeric_limits class, like this:

#include

double myQuietNan = std::numeric_limits::quiet_NaN();

double mySignalingNan = std::numeric_limits::signaling_NaN();

There are two kinds of NaN's - quiet and signaling.
a signaling NaN announces its presence in a floating point operation by throwing an exception. A quiet NaN does not raise an exception, but the results of using it in a floating point operation are not always obvious. You probably want to use the quiet NaN representation.

- Glenn
Message 2 of 4
(6,040 Views)
You can use the quiet_NaN method from the standard library numeric_limits class to do this. For example, if you're plotting data with CNiReal64Vector, you can #include <limits> and use numeric_limits::<double>quiet_NaN() to generate the NaN value. numeric_limits also has signaling_NaN, but you should use quiet_NaN if you want breaks in a plot. Plotting data that has signaling_NaN draws lines straight down from the preceding and next values rather than just leaving a gap.

- Elton
Message 3 of 4
(6,040 Views)
Thats just what I wanted, and it works a treat.
Many Thanks

Paul
0 Kudos
Message 4 of 4
(6,040 Views)