Compare — EQ / NE / GT / GE / LT / LE
Reference for Ladder Logic compare instructions in rungs.dev — EQ, NE, GT, GE, LT, LE — that pass power along a rung when the numeric relationship holds.
Compare two numeric values and pass power along the rung if the relationship holds. Compare instructions act like contacts — place them on the left side of a rung.
Available Compare Instructions
| Instruction | Symbol | Purpose |
|---|---|---|
EQ | EQ Source A sourceA Source B sourceB | Passes power when sourceA equals sourceB. |
NE | NE Source A sourceA Source B sourceB | Passes power when sourceA does not equal sourceB. |
GT | GT Source A sourceA Source B sourceB | Passes power when sourceA is greater than sourceB. |
GE | GE Source A sourceA Source B sourceB | Passes power when sourceA is greater than or equal to sourceB. |
LT | LT Source A sourceA Source B sourceB | Passes power when sourceA is less than sourceB. |
LE | LE Source A sourceA Source B sourceB | Passes power when sourceA is less than or equal to sourceB. |
Operands
| Name | Type |
|---|---|
sourceA | DINT | REAL |
sourceB | DINT | REAL |
Compare instructions do not operate on BOOL — use XIC / XIO for boolean checks. That includes comparing two bits to each other: EQ / NE on a pair of BOOL tags is a compile error, because contacts already express the question. Put the combinations on parallel branches.
"Are the two bits different?" — one branch for each way they can disagree:
0
A
B
A
B
Different
"Are they the same?" — one branch for both-on, one for both-off:
0
A
B
A
B
Same
The same rule applies in Structured Text, where the answer is XOR.
Example — Temperature Alarm
Turn on a cooling fan when temperature exceeds the setpoint.
0
GT
Source A
Temperature
Source B
75
Fan
Example — Value in Range
Energize InRange only when Pressure is between 20 and 100 inclusive.
0
GE
Source A
Pressure
Source B
20
LE
Source A
Pressure
Source B
100
InRange
Practice
Try comparisons in the Sign Check exercise — flag whether a number is negative, zero, or positive.
Common Mistakes
- Comparing a
BOOLtag — useXIC/XIOinstead. - Using
EQonREALvalues — fragile due to floating-point rounding. PreferGE/LEwith a small tolerance, orLIMIT.
Related
- LIMIT — range check in a single instruction
- Math instructions — compute values before comparing them
- MOVE — copy a value into a destination
- Bit instructions — boolean examine
NOP / AFI — No Operation and Always False
NOP and AFI in rungs.dev — NOP is a placeholder that does nothing, AFI forces the rest of its rung false. Both are used while building and debugging programs, not in finished logic.
LIMIT — Range Check
LIMIT in rungs.dev passes power when a test value is inside [lowLimit, highLimit]; if lowLimit is greater than highLimit, the bounds reverse to outside-the-band.