Skip to content

DIV — Divide

Category
Compute
Type
Output
Availability
All platforms

DIV instruction block: Source A Odo_km, Source B Hours, Dest Avg_kmh


DIV (Divide) writes Source A divided by Source B to Dest every scan its rung is true. It is an output instruction with no state and no status bits. Use DIV for an average, a rate, a ratio, or to split a total into equal parts. Do not use DIV when the divisor can be zero and Dest must change anyway; a zero divisor skips the write and Dest keeps its old value, so test the divisor first if that matters.


Operand Type Format Valid Range Required Description
Source A Any numeric tag, member, element or bit, or a literal Tag, Tag.Member, Tag[n], Tag.bit, or a literal Any resolvable numeric reference Yes The dividend.
Source B Same as Source A Same Any resolvable numeric reference; 0 skips the write Yes The divisor.
Dest A writable numeric tag, member or element Tag, Tag.Member, Tag[n] SINT, INT, DINT or REAL; not a literal, not an input pin Yes Where the quotient is written.

Whole numbers and fractions. The type of Dest decides how the division is done:

Sources Dest Result
Both whole numbers INT, SINT or DINT Whole-number division, truncated toward zero: 7 ÷ 2 is 3, −7 ÷ 2 is −3.
Both whole numbers REAL Floating-point division: 7 ÷ 2 is 3.5.
Either a REAL any Floating-point division; a whole-number Dest then truncates toward zero.

There is no remainder output. To get one, multiply the truncated quotient back and subtract, or use CPT with TRN.


Nothing. Dest keeps its power-up value.

The instruction does nothing. Dest holds its last value.

Both sources are read. If Source B is not zero the quotient is written to Dest. If Source B is zero nothing is written, Dest holds, and there is no fault.

Nothing.


Scenario: A delivery van logs kilometres and hours per trip. At the end of the trip the average speed is calculated for the run sheet.

Tags:

  • Trip_End — Trip complete, BOOL
  • Odo_km — Kilometres this trip, INT
  • Hours — Hours this trip, INT
  • Avg_kmh — Average speed, REAL

Rung 1:

—] [Trip_End———[DIV Odo_km Hours Avg_kmh]———

Scan 1 — Trip_End = 0. Odo_km reads 150 and Hours reads 4. The rung is false: Avg_kmh holds 0.

Figure 1 — DIV rung false: Odo_km 150, Hours 4, Avg_kmh 0, rung dark

Scan 2 — Trip_End = 1. 150 ÷ 4 is written. Both sources are whole numbers, but Avg_kmh is a REAL, so the division keeps the fraction: 37.5.

Figure 2 — DIV rung true: Avg_kmh reads 37.5, rung lit

Had Avg_kmh been declared INT, the same rung would show 37. Had Hours been 0, the rung would run and write nothing.


  • MUL — Multiply
  • CPT — Compute (division inside a longer expression; | is the divide symbol there)
  • SCP — Scale with Parameters (a ratio with an offset)
  • NEQ — Not Equal (guard a divisor against zero)
  • Compute Instructions — Category index

Zero divisor. RSLogix 500 faults the processor’s math overflow bit and writes the largest value; LadderIDE skips the write and leaves Dest alone, so a display keeps showing the last good value. Put NEQ Hours 0 ahead of the DIV when a stale value would mislead.

Remainder. Total ÷ 8 into an INT gives the whole quotient. The remainder is Total − Quotient × 8, two more instructions, or a single CPT Total − TRN(Total | 8) * 8.

Large DINT values. A REAL holds about seven significant digits. Dividing a DINT in the tens of millions into a REAL Dest loses the last digits; keep a DINT Dest for exact whole-number results.

The block never colours. Watch the rung wire and the Dest value line.

Applies to LadderIDE >=1.2.2 · Last reviewed 2026-09-11 · Screenshots verified 2026-09-11