I have to perform a calculation with 2 floating point numbers using measurements taken from a distance sensor with STM32. Calculation is carried out by following equation;
result = (df-ds)/ds*10000;
where df is first measurement and ds is second measurement.
Sample values for equation;
df = 26.6810; ds = 25.3270;
My problem is, STM32's result for these values is 534.578247, but when i do calculation on Windows' calculator manually i get the result of 534.607336 which is quite different from STM32's calculation. I've also used one hand-calculator and hand-calculator is giving out exactly same result with the computer.
All variables are declared as floats in the program. Why is there so much difference between two calculations? What kind of changes i could make to make STM32 give more precise results?
Thanks in advance for any help.
EDIT : The code i am using as follows;
float result= 0;
dmbres = 27.4587;
int main()
{
while(1)
{
result= (float)((dmbres- res)/res)*10000;
dmbres = res;
sprintf(datapackage, "%d;%.4f;%.6f\r\n", mid, res,result);
monitor(datapackage);
}
datapackage consists 2 other information i need from MCU and they are not relevant with the result calculation.
I am using STM32F407 DISC-1 board.