Skip to content

NEG — Negate

Category
Compute
Type
Output
Availability
All platforms

NEG instruction block: Source Offset, Dest Neg_Offset


NEG (Negate) writes the arithmetic negative of Source to Dest every scan its rung is true: a positive value becomes negative and a negative value becomes positive. It is an output instruction with no state and no status bits. Use NEG to reverse a direction command, mirror an offset, or flip the sign of a correction. Do not confuse it with NOT, which inverts every bit of a word; NEG 5 is −5, NOT 5 is −6.


Operand Type Format Valid Range Required Description
Source 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 value to negate.
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 negated value is written.

Dest may be the same tag as Source, in which case the value flips sign on every scan the rung is true. Gate that with an ONS or it flips thousands of times a second.

Range edge. The most negative value of a whole-number type has no positive twin: NEG of −32768 in an INT wraps back to −32768. A REAL has no such edge.


Nothing. Dest keeps its power-up value.

The instruction does nothing. Dest holds its last value.

Source is read, its sign is reversed and the result is written to Dest every scan the rung is true.

Nothing.


Scenario: A positioning table applies a tool offset when travelling forward. On the return pass the same offset must be applied the other way.

Tags:

  • Reverse — Return pass, BOOL
  • Offset — Tool offset in steps, INT
  • Neg_Offset — Offset for the return pass, INT

Rung 1:

—] [Reverse———[NEG Offset Neg_Offset]———

Scan 1 — Reverse = 0. Offset reads 250. The rung is false: Neg_Offset holds 0.

Figure 1 — NEG rung false: Offset 250, Neg_Offset 0, rung dark

Scan 2 — Reverse = 1. Neg_Offset reads −250.

Figure 2 — NEG rung true: Neg_Offset reads −250, rung lit


  • ABS — Absolute Value (the sign removed rather than reversed)
  • SUB — Subtract (SUB 0 Source Dest is the same operation)
  • NOT — Bitwise NOT (inverts bits, not sign)
  • Compute Instructions — Category index

Toggle sign. NEG Dir Dir behind an ONS alternates a direction value between +1 and −1 on each event.

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