Configuration | Rules 4.2.1.3.11 SA0054: Comparisons of REAL/LREAL for equality/inequality | SA0054: Comparisons of REAL/LREAL for equality/inequality Samples: PROGRAM MAIN VAR fREAL1 : REAL; fREAL2 : REAL; fLREAL1 : LREAL; fLREAL2 : LREAL; bResult : BOOL; END_VAR bResult := (fREAL1 = fREAL1); // => SA0054 bResult := (fREAL1 = fREAL2); // => SA0054 bResult := (fREAL1 fREAL2); // => SA0054 bResult := (fLREAL1 = fLREAL1); // => SA0054 bResult := (fLREAL1 = fLREAL2); // => SA0054 bResult := (fLREAL2 fLREAL2); // => SA0054 bResult := (fREAL1 > fREAL2); // no error bResult := (fLREAL1 4.2.1.3.12 SA0055: Unnecessary comparison operations of unsigned operands | SA0055:
Unnecessary comparison operations of unsigned opera ... Samples: PROGRAM MAIN VAR nBYTE : BYTE; nWORD : WORD; nDWORD : DWORD; nLWORD : LWORD; nUSINT : USINT; nUINT : UINT; nUDINT : UDINT; TE1200 44 Version: 2.11.1 Function Determines where the comparison operators = (equality) and (inequality) compare operands of type REAL or LREAL. Reason REAL/LREAL values are implemented as floating point numbers in accordance with the IEEE 754 standard. This standard implies that certain seemingly simple decimal numbers cannot be represented exactly. As a result, the same decimal number may have different LREAL representations. Sample:
fLREAL 11 := 1.1; _ fLREAL 33 := 3.3; _ fLREAL a := fLREAL 11 + fLREAL 11; _ _ _ fLREAL b := fLREAL 33- fLREAL 11; _ _ _ bTest := fLREAL a = fLREAL b; _ _ bTest will return FALSE in this case, even if the variables fLREAL a and fLREAL b both _ _ return the monitoring value "2.2". This is not a compiler error, but a property of the floating point units of all common processors. You can avoid this by specifying a minimum value by which the values may differ: bTest := ABS(fLREAL a - fLREAL b) Exception A comparison with 0.0 is not reported by this analysis. For 0 there is an exact representation in the IEEE 754 standard and therefore the comparison normally works as expected.
For better performance, it therefore makes sense to allow a direct comparison here. Importance High PLCopen rule CP54 Function Determines unnecessary comparisons with unsigned operands. An unsigned data type is never less than zero. Reason A comparison revealed by this check provides a constant result and indicates an error in the code. Importance High