Tool/software: Code Composer Studio
I know there is a recommendation to avoid floats - but we are porting some code as a POC ...
Can you help me understand why the following code produces incorrect results?
float testArray1[] = { 0.0, 1.0, 2.0, 1.22, 4.0, -1.802299, 6.0, 7.1234, 8.0, 9.0, 10.0, -11.9876, 12.0, 13.0, 14.0, 15.0, 16.0,
17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 9999.0};
float *fvalue = (float *) 0x10000; // force "far" pointer to be created
void test()
{
...
for(i=0; i<NUMBER_TEST_ELEMENTS; i++)
{
uartA0IntValue(" [", i);
uartA0FloatValue("]:", testArray1[i]);
}
...
}
Produces the following:
[0]:0.0 [1]:1.0 [2]:2.0 [3]:1.22000 [4]:4.0 [5]:-1.32767 [6]:6.0 [7]:7.12340 [8]:8.0 [9]:9.0 [10]:10.0 [11]:-11.32767 [12]:12.0 [13]:13.0 [14]:14.0 [15]:15.0 [16]:16.0 [17]:17.0 [18]:18.0 [19]:19.0 [20]:20.0 [21]:21.0 [22]:22.0 [23]:23.0 [24]:24.0 [25]:9999.0
[5] should be: -1.802299 BUT instead is -1.32767
[11] should be: -11.9876 BUT instead is: -11.32767