CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

NaN Check

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sei500510



Joined: 19 Oct 2011
Posts: 2

View user's profile Send private message

NaN Check
PostPosted: Wed Oct 19, 2011 7:49 am     Reply with quote

hi,
how to check if float number is NAN?

IF (n != n)
...

don't work. Sad
Thanks

VC
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Oct 19, 2011 8:05 am     Reply with quote

Code:
IF (n != n)


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

View user's profile Send private message

PostPosted: Wed Oct 19, 2011 8:55 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 19, 2011 9:39 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 19, 2011 4:16 pm     Reply with quote

This thread has a discussion of methods to recognize if the eeprom data is
all equal to 0xFF:
http://www.ccsinfo.com/forum/viewtopic.php?t=40718
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group