LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

literal NaN

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

0 Kudos
Message 1 of 21
(4,383 Views)
Do you mean something different from using NotANumber () from the Programmer's toolbox?


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 21
(4,383 Views)

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.

0 Kudos
Message 3 of 21
(4,373 Views)

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.

Message Edited by Makoto on 06-17-2010 05:17 PM
0 Kudos
Message 4 of 21
(4,352 Views)
Edited: Wrote rubbish, sorry!
Message Edited by msaxon on 17-06-2010 09:47 AM
--
Martin
Certified CVI Developer
0 Kudos
Message 5 of 21
(4,346 Views)

Could you do something like 

number = (float)0xFFFFFFFF;

?

0 Kudos
Message 6 of 21
(4,329 Views)

Only if you wanted number to be -1.0!

 

JR

Message 7 of 21
(4,327 Views)

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

0 Kudos
Message 8 of 21
(4,307 Views)
0xFFFFFFFF should be NaN, -1.0 would be 0xBF800000. As long as the compiler makes sure the variable is initialized to the proper bits it should work, correct?
0 Kudos
Message 9 of 21
(4,303 Views)

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

0 Kudos
Message 10 of 21
(4,301 Views)