Comparison Operators¶
Comparison operators compare two values and produce a BOOL result.
IEC 61131-3 |
Section 3.3.1 |
Support |
Supported |
Syntax¶
Operator |
Syntax |
Description |
|---|---|---|
|
|
Equal to |
|
|
Not equal to |
|
|
Less than |
|
|
Greater than |
|
|
Less than or equal to |
|
|
Greater than or equal to |
Description¶
Comparison operators compare two operands of the same type and return a
BOOL value. They apply to integer types (SINT, INT, DINT,
LINT, USINT, UINT, UDINT, ULINT) and floating-point types
(REAL, LREAL).
When the two operands have different types and one widens to the other, the
comparison is done at the wider type, whichever side it is on: a DINT
compared with a LINT is compared as a LINT, and a DATE_AND_TIME
compared with an LDATE_AND_TIME as an LDATE_AND_TIME.
When neither operand type widens to the other, such as DINT and
UDINT or DINT and REAL, no type holds both operands and the
comparison is rejected with P4049. Convert
one operand explicitly to a type that holds both. An untyped literal takes
the type of the other operand when that type’s category holds it: u > 3
compares at the type of u.
Equality (=, <>) has lower precedence than the relational operators
(<, >, <=, >=). Both groups have lower precedence than
arithmetic operators.
Example¶
PROGRAM main
VAR
temperature : INT := 75;
setpoint : INT := 70;
overheat : BOOL;
at_target : BOOL;
END_VAR
overheat := temperature > setpoint;
at_target := temperature = setpoint;
END_PROGRAM
See Also¶
Arithmetic Operators — numeric operators
Logical Operators — boolean operators
IF — conditional branching using boolean expressions