NaN macros not working correctly?

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm running AS 7.0.1645

toolchain 7.0.895

 

I have an un-initialized float nanCheck that the debugger reports as -nan(0x7fffff).

But

isnan( nanCheck ) returns 0 // (FAIL!)

fpclassify( nanCheck ) returns FP_NORMAL // (FAIL!)

nanCheck += 1; // nanCheck remains unchanged (correct!)

nanCheck *= 0; // nanCheck == 0 (FAIL!)

if( nanCheck != nanCheck ) // optimized out (FAIL!)



float foo = nanCheck;

if( foo != nanCheck ) // works (correct!)

 

I read in the AVR forum that they got a new library that finally fixed the floating point stuff.  Is there such an update for the ARM platform also?

If so, how and where do I get it ?

If not, is anyone at Atmel aware of this issue?

 

Thanks,

Aaron

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If the variable is uninitialized, anything goes. That's because using the value of an uninitialized variable is undefined behavior. The compiler can make any kind of assumption about its value and optimize using those assumptions, even if the assumptions don't all make sense when put together.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You had me hopeful there for a bit, but alas it still fails.

 

// arm_math.h defines: #define NAN (0.0F/0.0F)

float foo = NAN; // foo == nan(0x400000)
uint16_t bar;
	
bar = isnan( foo ); // bar == 0 (FAIL!)