This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ieee float -1#nan value

Hi,
I accidentally stuff the value of 0xFFFF into a float variable (fVal). My emulator shows me its value is -1#nan (not a number) and my limit clipping code did not work on this value

ie,

if (fVal > fMax) fVal = fMax;
else if (fVal < fMin) fVal = fMin;

You'd think that the fVal would always be inside the limits of fMin and fMax for all values of fVal, but the code did not work when fVal contains the -1#nan value. How should I handle this? Is this a compiler bug?

Thanks
Andy

Parents
  • How should I handle this?

    Probably not at all. ;-) The behaviour you got is exactly expected from a NaN value: all comparisons you make that involve a NaN, will return "false". An old trick to detect them thus always was:

    if (!(fVal == fVal)) {
    	/* Ouch! fVal is a NaN. Now what? */
    }

    Is this a compiler bug?

    No. Expected behaviour. Even required, if you want to follow IEEE floating point arithmetics.

Reply
  • How should I handle this?

    Probably not at all. ;-) The behaviour you got is exactly expected from a NaN value: all comparisons you make that involve a NaN, will return "false". An old trick to detect them thus always was:

    if (!(fVal == fVal)) {
    	/* Ouch! fVal is a NaN. Now what? */
    }

    Is this a compiler bug?

    No. Expected behaviour. Even required, if you want to follow IEEE floating point arithmetics.

Children
No data