Hi,
I'll perform some calculations in the CCS (Code Composer Studio). When a variable is declared as a float or double, calculations produce inaccurate results.
How to solve the problem.
alu_calculation = 7.7 + 2.4 = 10.1
alu_calculation = 9.8 - 5.6 = 4.2000000000000011 (wrong)
alu_calculation = 5.9 * 2.7 = 15.930000000000001 (wrong)
This is code:
//*************************************************************************************
static unsigned int Status_ALU = 0;
double alu_calculation = 0.000;
alu_calculation = 7.7 + 2.4;
if(alu_calculation == 10.100000)
{
alu_calculation = 0.000;
alu_calculation = 9.8 - 5.6;
if(alu_calculation == 4.2)
{
Status_ALU = 1;
}
}
else
{
Status_ALU = 0;
}
if(Status_ALU == 1)
{
alu_calculation = 5.9 * 2.7;
if(alu_calculation == 15.93)
{
Status_ALU = 1;
}
}
else
{
Status_ALU = 0;
}
//************************************************************************************
Regard,
Vijay