I just kind of wanted to propose a general discussion.
I've recently implemented a program in an Allen Bradley PLC. One of the lines of code used is the following:
The variables 'Value', 'Distance', and 'Dwell' were declared as REAL (floating point) data types.
In a specific scenario, the value of Distance is 100.0 and the value of Dwell was 0.7. Now if you do the math, you realize that this expression should assign the value of 15.0 to 'Output'.
However, what is really being outputted is a value of 15.000001. I assume this is do to a loss of precision from using the floating point data type.
My questions for all of you are: Have you ran into troubles with this before? How have you remedied it? Did you make it so that your program logic would not be affected by this slight error?
I'm working specifically on motion logic and am getting compilation errors due to this so the topic has come of interest.
I've recently implemented a program in an Allen Bradley PLC. One of the lines of code used is the following:
Output := (Distance/2)-(Distance*(Dwell/2));
The variables 'Value', 'Distance', and 'Dwell' were declared as REAL (floating point) data types.
In a specific scenario, the value of Distance is 100.0 and the value of Dwell was 0.7. Now if you do the math, you realize that this expression should assign the value of 15.0 to 'Output'.
However, what is really being outputted is a value of 15.000001. I assume this is do to a loss of precision from using the floating point data type.
My questions for all of you are: Have you ran into troubles with this before? How have you remedied it? Did you make it so that your program logic would not be affected by this slight error?
I'm working specifically on motion logic and am getting compilation errors due to this so the topic has come of interest.