Chapter 10
Compare instructions
Example: Comparing Real Values using Subtraction (-) ABS, and Less than
(<)
The Real data type is not recommended when comparing values for equality
because of differences in the way numbers are rounded. Two output values may
appear equal in a Connected Components Workbench display, but will evaluate as
false.
For example, 23.500001 compared to 23.499999 will both display as 23.5 in the
variable input display, but will not be equal in the controller.
To test whether two Real data type values are equal, you can use a Subtraction
instruction to get the difference between the values and then determine if the
difference is Less Than an established precision value. See the following LD
program example for comparing two Real data type values.
Equal (=) operator ST language example
Example
(* ST Equivalence: *)
aresult := (10 = 25); (* aresult is FALSE *)
mresult := ('ab' = 'ab'); (* mresult is TRUE *)
Rockwell Automation Publication 2080-RM001D-EN-E - February 2015
261