View previous topic :: View next topic |
Author |
Message |
VanHauser
Joined: 03 Oct 2005 Posts: 88 Location: Ploiesti, Romania
|
"Not-a-number" and +/-Infinity floats |
Posted: Wed May 23, 2012 2:04 pm |
|
|
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
|
|
Posted: Wed May 23, 2012 2:37 pm |
|
|
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
|
|
Posted: Wed May 23, 2012 2:52 pm |
|
|
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
|
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu May 24, 2012 1:49 am |
|
|
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 |
|
|
|