Hello,
I am using 89C51ED2 for solving non-linear equations. I am facing accuracy problems while doing floating point arithmetic. The accuracy of floating point arithmetic is limited to 3 decimal points thus leading to an erroneous results after a series of operations. Declaring variables as double doesn't solve the problem.How can I increase accuracy of floating point operations? Is there any way to solve this issue?
Thanks in advance.
Praveen K
You mean 3 decimal places? Not sure that's how floats even work, its the number of significant digits that is limited.
You should probably check the maths, and the casting, and make sure you aren't throwing the precision out. Understand the scale of your numbers throughout the calculation. Rearrange the math if required.
The least significant digits are the ones most at risk with floating point math. If you are dealing with very large numbers, try to remove those before doing the math that requires precision.
Consider fixed point, BCD, bignum, etc. Review chapters on numeric representation
Why ???
It's got what plants crave..
Perhaps in time the warehouse or fab for these parts will collapse.
The answer for 'WHY' is - application demands I am using a 8051 based portable auto-calibrator which fetches values from a field sensor. The sensor output is related to measured parameter by a 2nd degree polynomial equation whose coefficients are obtained during multi-point calibration. Auto-calibrator need to fit 10 calibration points using least-square curve fitting method. Curve-fitting algorithm uses floating-point arithmetic.
Thanks for your reply Mr.Pier
Yes, I mean to say '3 decimal places'. As you pointed out correctly, the issue is with the limitation in number of significant digits. While debugging I can clearly see the difference in least significant digits during each floating-point operation. After a sequence of operations,it finally lead to a wrong result. Is this limitation of 8051 floating point arithmetic? I tried running the same code in a DevC++ compiler, but the result was same.
Keil supports 32bit float only. Using double does not change this.
You may buy a product like in
www.smxrtos.com/.../gofast_8051.htm
or if you don't mind code space or run time port/compile some public domain source code of a floating point source code from other platforms.
PS: My answer implies that you really need this, which I can not know.