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 CCS Technical Support

"Not-a-number" and +/-Infinity floats

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



Joined: 03 Oct 2005
Posts: 88
Location: Ploiesti, Romania

View user's profile Send private message

"Not-a-number" and +/-Infinity floats
PostPosted: Wed May 23, 2012 2:04 pm     Reply with quote

I have an application that uses a constant table made of float values. In this table I have some cells that should be empty (no value defined) and I need to mark these, either with Infinity or NaN (not a number).

Is there any way to assign such "values" to cells in my table and test for them in the code? Thanks.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed May 23, 2012 2:37 pm     Reply with quote

I haven't tested it, but I presume all possible codes convert to a valid float value, much as they do for integers.

In that case, all I can suggest is that you load the "empty" cells with one of the two extreme float values and test for that.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Wed May 23, 2012 2:52 pm     Reply with quote

0xFFFFFFFF is defined as NAN, both in CCS float32, and in IEEE float32.

As far as I know there is no way to actually 'test' this if loaded into a float value, but if you load the values into a union with an int32, and a float as the two stored 'types', and test for 0xFFFFFFFF in the int32, this value van never occur legitimately from a float value. You can verify this if you try putting this into the Pconvert program.


Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 23, 2012 10:33 pm     Reply with quote

This thread and the link in it discuss the "NaN" topic:
http://www.ccsinfo.com/forum/viewtopic.php?t=46566
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Thu May 24, 2012 1:49 am     Reply with quote

BEWARE: Don't expect CCS floating point code to conform to IEEE754 with regard to NaNs and the like. CCS C will not do what you might expect. Indeed until IEEE754 came along there were very few floating point formats that did implement any systematic concept of anything like NaNs and infinities.

Before IEEE754 there many, many FP formats, not just on processors but on compilers from different suppliers targeting the same processors, Just about everyone did their own thing and there was little or no standardisation. There still are different non-standard FP formats out there, especeially on processors that do not have FP hardware available. CCS C's being just one of them.

As it targets a PIC, with limited processing capabilities, CCS C FP is simple and basic, Don't expect it to be all things to all men. From some of the threads on this forum, don't even expect it to be particularly "accurate". Especially, it seems, when measuring the distance between two close together locations on the earth....

RF Developer
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