LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Does the Not A Number type has an equivalent constant in CVI code?

In case of divide by 0 operation, CVI set the result at NaN, but I cannot find the equivalent constant in the code to test and manage the result of my division (if (Result==NAN_CONSTANT)...)does it exists?
0 Kudos
Message 1 of 5
(3,928 Views)
In CVI 6.0, ivi.h contains a Not a Number constant IVI_VAL_NAN based on the IEEE 754 special value. You can paste the following code into the Interactive Execution window to test it. Note that when you try to print a variable set to IVI_VAL_NAN, "NaN" is printed.

#include
#include
static double x1, x2;

x1 = IVI_VAL_NAN;
x2 = x1;
printf("x2 = %f\n", x2);
if (x2 == IVI_VAL_NAN)
printf("x2 is Not a Number.\n");
Message 2 of 5
(3,928 Views)
I have try this code, but if you set x2 to a number value (5.5 for example), the code still print on the screen "x2 is Not a Number"....Have I done something in a wrong way (include?) Can you check it please?
0 Kudos
Message 3 of 5
(3,928 Views)
Sorry, I haven't been able to figure this out either. Maybe you need to deconstruct the floating point number and verify that the exponent = 0xFF and the mantissa != 0.
Check these sites.
http://www.psc.edu/general/software/packages/ieee/ieee.html
http://community.borland.com/article/0,1410,16716,00.html
The Borland article looks like its using the IEEE single, not double, but I haven't gone through it or tried it yet.
0 Kudos
Message 4 of 5
(3,928 Views)
The solution I apply in my code is to create a constant TYPE_NAN, with the function ldexp(mantissa,exponent) and values that define a NaN in the IEEE754 (TYPE_NAN=ldexp(1,0xFF). After that I can compare my variables to the TYPE_NAN, and it works.
have a good day.
0 Kudos
Message 5 of 5
(3,928 Views)