# Compare — EQ / NE / GT / GE / LT / LE

Source: https://rungs.dev/docs/ladder-logic/instructions/compare

> 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 [#available-compare-instructions]

| Instruction | Symbol                          | Purpose                                                        |
| ----------- | ------------------------------- | -------------------------------------------------------------- |
| `EQ`        |  | Passes power when sourceA equals sourceB.                      |
| `NE`        |  | Passes power when sourceA does not equal sourceB.              |
| `GT`        |  | Passes power when sourceA is greater than sourceB.             |
| `GE`        |  | Passes power when sourceA is greater than or equal to sourceB. |
| `LT`        |  | Passes power when sourceA is less than sourceB.                |
| `LE`        |  | Passes power when sourceA is less than or equal to sourceB.    |

## Operands [#operands]

| Name      | Type                                |
| --------- | ----------------------------------- |
| `sourceA` | `DINT` \| `INT` \| `SINT` \| `REAL` |
| `sourceB` | `DINT` \| `INT` \| `SINT` \| `REAL` |

Compare instructions do not operate on `BOOL` — use [`XIC`](https://rungs.dev/docs/ladder-logic/instructions/xic) / [`XIO`](https://rungs.dev/docs/ladder-logic/instructions/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:

```ladder
[XIC(A)XIO(B),XIO(A)XIC(B)]OTE(Different)
```

"Are they the same?" — one branch for both-on, one for both-off:

```ladder
[XIC(A)XIC(B),XIO(A)XIO(B)]OTE(Same)
```

The same rule applies in Structured Text, where the answer is [`XOR`](https://rungs.dev/docs/structured-text/arithmetic-and-comparison-operators#comparing-bools).

## Example — Temperature Alarm [#example--temperature-alarm]

Turn on a cooling fan when temperature exceeds the setpoint.

```ladder
GT(Temperature,75)OTE(Fan)
```

## Example — Value in Range [#example--value-in-range]

Energize `InRange` only when `Pressure` is between 20 and 100 inclusive.

```ladder
GE(Pressure,20)LE(Pressure,100)OTE(InRange)
```

> **IDEA**
>
> **Practice**
>
> Try comparisons in the [Sign Check exercise](https://rungs.dev/exercises/sign-check) — flag whether a number is negative, zero, or positive.

## Common Mistakes [#common-mistakes]

- Comparing a `BOOL` tag — use `XIC` / `XIO` instead.
- Using `EQ` on `REAL` values — fragile due to floating-point rounding. Prefer `GE` / `LE` with a small tolerance, or [`LIMIT`](https://rungs.dev/docs/ladder-logic/instructions/limit).

## Related [#related]

- [LIMIT](https://rungs.dev/docs/ladder-logic/instructions/limit) — range check in a single instruction
- [Math instructions](https://rungs.dev/docs/ladder-logic/instructions/math) — compute values before comparing them
- [MOVE](https://rungs.dev/docs/ladder-logic/instructions/move) — copy a value into a destination
- [Bit instructions](https://rungs.dev/docs/ladder-logic/instructions/bit-instructions) — boolean examine