View previous topic :: View next topic |
Author |
Message |
sei500510
Joined: 19 Oct 2011 Posts: 2
|
NaN Check |
Posted: Wed Oct 19, 2011 7:49 am |
|
|
hi,
how to check if float number is NAN?
IF (n != n)
...
don't work.
Thanks
VC |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Wed Oct 19, 2011 8:05 am |
|
|
that reads "if this value is not equal to the same value"
that is impossible... the value cant be 2 values at the same time.
in other words:
IF(1 Not equal to 1)
this will always fail as 1 is always equal to 1.
... you should better explain what you are trying to do.
g _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
sei500510
Joined: 19 Oct 2011 Posts: 2
|
|
Posted: Wed Oct 19, 2011 8:55 am |
|
|
Thanks Gabriel
if you look here:
http://en.wikipedia.org/wiki/NaN
you will find the example of code, but this trick don't work in CCS.
I want to read a floating number stored in eeprom. The first time, all the cells of eeprom contain 0xFF so the read_float_eeprom() return NAN
VC |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Wed Oct 19, 2011 9:39 am |
|
|
Then... you could define a range of "Valid" numbers, and if the number you read falls in this range its valid, else NAN.
Then again... 0xFF is a "valid" number (max 8 bit reading of ADC) so its still unclear what you are trying to do.
You want to know if the EEprom contains "real" data or if is still in its reset (0xff) state. Is this correct?
If so... unless 0xff is not a posible value in your stored data, then i do not see a way to determine this by just reading the value.
g. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|