This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/F28M35H52C: Looking for information on floating point NaN constant

Part Number: F28M35H52C

Tool/software: TI C/C++ Compiler

Good morning,

I am programming the Concerto part on the Master (ARM) side.  The math.h header file has some references in it to what appear to be Compiler constants, such as __NAN__ and __INFINITY__.

I have been unable however, to

1) find any reference to where these constants are defined or

2) any reference to their usage, other than the header file.

What I'm looking for is a clear #define for a NAN that I can use in my code as an error reply to a malformed data request over a communciations system.  Something similar to the _FP_ILOGBNAN define, which is 0x7FFFFFFF.  This is a nice, single precision float value that represents one possible NAN.  However, this particular define is wrapped in a #if _ILONG which now begs the question, where is _ILONG defined?

I can't use these header constants without further understanding of all of the conditionals that the header is dependent on, some of which appear to be tool/ environment constants.

Thank you and best regards,

Steve Ciricillo

  • If it compiles OK, just right-click and go to the definition.
  • Those macros are compiler built-ins that correspond to IEEE-754 values. See IEEE-754 for a precise specification.
    There is not a single value for NaN; it is a wide range of possible bit encodings, although the TI compiler only supports one, which is equivalent to a QNaN as described by IEEE-754.
    Try:
    en.wikipedia.org/.../NaN
    en.wikipedia.org/.../IEEE_754-1985
  • Thanks Archaeologist. Your links are helpful to my understanding about floating point implementations.
    I am however still curious about the specific implementation in the compiler I am using. You said that _NAN_ and _INFINITY_ are compiler macro built-ins. I guess they just aren't "built in" to the documentation?
  • You are meant to use NAN and INFINITY, which are C99 macros defined in math.h, and they are defined by the C99 standard, so we do not document them ourselves.

    I'm sorry, I should not have said that __NAN__ and __INFINITY__ are macros; they are not. They are compiler builtins, like intrinsics and attributes.
  • I think it is meant to use "isnan()" and "isinf()" which are defined in math.h as opposed to some #define macros.
  • I want to write a function that returns a NaN under a failure condition. What I'm looking for is a standard constant to load into a float variable as the return value. I don't need to test a value for whether it's a Nan or not. That's the calling function's problem.
  • Thanks again Arch. I get it. C99 defines these things so math.h doesn't really have too. OK, but I still wonder about the builtins you reference. Can't find any documentation on those and it seems that would be obligatory for TI to put in their compiler manuals. Anyway, moving on and using NAN to solve my issue.
  • So that statement "The wonderful thing about standards is that there are so many to choose from..." I think applies.
    I am not sure about your particular processor family, but I know the C6000 DSPs while support the IEEE Floating point standard, did not support NAN and INF. I had to add that support myself. I defined my own NAN and INF (well I used the same definitions that are in IEEE standard).
  • None of the TI compilers supported "NAN" or "INFINITY" until we started adding C99 support. At that time, all of the compilers, including C6000, were upgraded to provide explicit macros NAN and INFINITY in math.h

    This support was rolled out in bits and pieces, so you may find some inconsistent behavior between the various compilers for TI architectures in that time period.

    If you are using an older compiler, you can always (as Mike suggests) make your own constants (e.g. on C6000: #define INFINITYF _itof(0x7f800000)), or an expression that generates such a value (1.0/0).