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.

float assignment results in NaN

Other Parts Discussed in Thread: MSP430G2955

I'm using CCS 6.1.0.00104 with an MSP430G2955.

I have a global variable float f1 initialized to 0.0.

I have a second local variable float f2 which can be from 0.0 to -10.00 and for this example = -5.03.

The C line

f1 = f2;

 results in f1 = NaN.

Why is this happening?

Thanks for any insight.

  • Okay, so i changed my program such that I make the above assignment by returning f2 from a function call:

    f1 = somefunc();


    This gives correct result for f1.

    Some compiler quirk?
  • I'm sorry, I cannot reproduce the error. Could you post a complete test case, including all of the command line options? How do you know the result is NaN; are you looking at it in the watch window?
  • eltury said:

    The C line

    f1 = f2;

     results in f1 = NaN.

    It is likely whatever went wrong happened before this point, possibly long before this point.  One wild guess ... the stack overflowed.  Exactly how do you observe that, right before this assignment, f2 contains -5.03?

    Thanks and regards,

    -George

  • I was in debug mode and had f1 & f2 in a watch window. Breakpoint on line above the assignment then single stepped the assignment line and f1 became NaN. Also noticed that once in a while instead of NaN I got an extrememly small number - -45 for exponent.
  • Just like Archeaologist said, we need a test case we can build and directly see this behavior.  If this is organized as a CCS project, it would be ideal if you submitted it.

    Thanks and regards,

    -George

  • I will do that when I get a chance.
    Thanks.