AWC application engineers had some totals on a recent application drifting away, which reflects an issue with precision when summing large volume floating-point numbers.
- Floating-point values have 6 digits of precision in the PLC (P).
- Data has S significant digits.
- 10^(P–S) values can be safely summed without losing precision.
- For a PLC application in which 4 significant digits are required, 10^(6-4) = 100 values that can be summed without losing precision.
As evidenced in the above screenshot, the usual summation style lacks accuracy and can only get worse if the number of digits increased above what the mantissa could manage. If the application requires data types to be kept as 32-bit floats for whatever reason, implementing the Kahan block will prevent any totals from drifting away. Please fill out the below form if you are interested in using the Kahan block for your own application.
- Julyann Tu – AWC, Inc.