06-16-2010 03:51 PM
Is there a way to specify a literal Not a Number (NaN) in CVI? I.e., a constant value that is the IEEE NaN.
That way, you could initialize static and top level variables as NaN, since even C99 requires constant initializer for these.
Other languages provide this, some with a static class variable, others through the use of a macro.
Menchar
06-16-2010 04:20 PM
06-16-2010 06:49 PM
Right. A literal NaN, not a function call like NotANumber();
Some implementations (OO languages) use a static field in a class like "Math.NaN" and some use a macro like NAN to tell the compiler to generate the NaN as a constant, rather than doing it at runtime with the N otANumber() function.
06-17-2010 03:12 AM - edited 06-17-2010 03:17 AM
Standard C languages including CVI do not suuport pre-defined expression for NaN, Inf, Ninf.
But IVI's "ivifloat.dll" supports some functions that return such values:
ViReal64 _VI_FUNC IviFloat_PosInf(void);
ViReal64 _VI_FUNC IviFloat_NegInf(void);
ViReal64 _VI_FUNC IviFloat_NaN(void);
Include IviFloat.h and link IviFloat.lib with your CVI project. The DLL comes with IVI Shared Components package or (probably) recent LabWindows/CVI. The DLL/.h/.lib files will be found in C:/Program Files/IVI Foundation/IVI directory.
If you want use them as if literal, just keep the returned values to global vars or #define symbols.
06-17-2010 03:41 AM - edited 06-17-2010 03:47 AM
06-17-2010 07:33 AM
Could you do something like
number = (float)0xFFFFFFFF;
?
06-17-2010 07:54 AM
Only if you wanted number to be -1.0!
JR
06-17-2010 11:10 AM
My point was to get the compiler to generate the value as a constant, not as a function call.
C99 defines FP_NAN as just such a constant in math.h. but NI has not implemented this constant or any of the other FP_ constants or functions defined in C99, such as
FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, isnan(), isfinite(), usnormal(), etc.
While NI has put some NaN support in the programmer's toolbox, implementing the C99 standard NaN support woud be a better deal.
I had mentioned this way back when we petitioned NI to update the standard compiler to C99, but this particular feature never made the grade apparently.
Menchar
06-17-2010 11:27 AM
06-17-2010 11:39 AM
No! The unadorned value 0xFFFFFFFF is equivalent to -1.0, for the vast majority of compilers. If you could put that bit pattern into the storage area used by a float, then yes it would represent NaN, but the = operator will not do that job for you. You could achieve this effect with a union:
union {
float f;
int i;
} un;
so that setting un.i = 0xFFFFFFFF would then yield un.f to be NaN, but this is a long way short of the OP's requirements for a constant initialiser.
JR