This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C1294NCPDT: Floating point Issue

Part Number: TM4C1294NCPDT


Hi, 

I am facing issue in floating point operation in TM4C1294. when i am incrementing float value from 0.6 to 0.7 by 0.1 then variable in watch window shows 0.699999..  which is actually causing problem . I am attaching screenshot for such issue. Part of code is below


if(UP_KEY==0 )
{

if(UP_KEY==0 )
{
count++;
}
else
{
count=0;
}
if(count>10 )
{
count=15;
Set_point[channel_no]+=1.0;
}
else
{
Set_point[channel_no]+=0.1;
}


if(Set_point[channel_no]>300.0)//3.3//300.0
{
Set_point[channel_no]=0.0;
}
}

check value of Set_point[0] in watch window and is 2.20000005, after incrementing value by 0.1 the value has to be 2.30000 but it is 2.29999995 as shown in below image

Please help to correct this.

Regards

Khodidas

  • Hi,

      A couple of questions?

      - Are you using the hardware FPU or the software way to do the floating? Can you call FPUEnable() before you start your floating operations so the hardware floating point unit will perform the work.

      - Can you try with different optimization levels? Are you seeing the same issue?

      - There are a couple FPU related APIs. Can you try them to see if any one makes a difference? 

  • check value of Set_point[0] in watch window and is 2.20000005, after incrementing value by 0.1 the value has to be 2.30000 but it is 2.29999995 as shown in below image

    Some decimal values can't be represented exactly in IEEE-754 Floating Point format.

    IEEE-754 Floating Point Converter can show the "Error due to conversion" when trying to store a requested decimal value in a 32 bit – float (aka single precision) which has hardware support in the Cortex-M4F CPU in a TM4C1294NCPDT. Example for 2.30000 :

    Base Convert: IEEE 754 Floating Point can show the increased precision of using a 64-bit double. E.g.:

    The Cortex-M4F doesn't have hardware support for 64-bit double, so using them is done in software which is slower.

  • Hi Chester,

      Thanks for providing the detailed information. I think it explains. 

  • Hi, 

    I have tried all of your suggestion but not worked, at the end I implemented correction in firmware for the need of application. I came to know from IEE754 Floating point found error due to conversion, so, is there any method to use the error to correct value.

    Regards

    Khodidas