Comparing REAL values as EQUAL
It is often hard to get two REALS to be exactly the same, hence are not EQUAL
REAL datatypes are very useful in programming. They allow us to store large and small values and include a useful amount of precision. There are REALS (4 byte) and LREALS (8 byte) which vary in the precision and range of values they can represent.
However when working with REAL data types it is important to remember that they are an approximation of a number. As such, they are often not quite equal to the number we expect, but they are so close, that the error between our expected value and the actual value is so small as to be inconsequential.
However when comparing two REAL values, we sometimes don't get the result we expect. This is because for computers, 1.99999999 is not equal to 2. For all intends and purposes it is, the error is so minute we do not care. But computers, including Machine Controllers care, these two values are NOT equal.
To get around this problem, we often compare a number to another number using an upper and lower bound of precision. For instance we can determine if two numbers are practically equal by the following code. The fixed value of 0.0001 can easily be a precision level we pass to a Function which does this comparison and returns TRUE if realVal1 is practically equal to realVal2
equal:= ((realVal1 + 0.0001) > realVal2 AND (realVal1 - 0.0001) < realVal2);