ABS / SQRT / NEG — One-Input Math

Reference for the one-input Ladder Logic math instructions in rungs.dev — ABS (absolute value), SQRT (square root), and NEG (negate). Each reads one Source and writes one Dest.

The math instructions you have met so far combine two sources. These three work on a single value: they read Source, transform it, and write the result to Dest every scan the rung is true. Like all math blocks, they live in the Math tab of the ladder toolbar, and Source can be a tag or a typed-in number.

InstructionWrites to Dest
ABSSource with the minus sign dropped
SQRTthe square root of Source
NEG0 − Source (sign flipped)

ABS — Absolute Value

Drops the minus sign: -5 becomes 5, and values that are already positive pass through unchanged. Useful when you care about how far a value is from zero but not which side it is on — for example, turning a temperature error of -3.2 degrees into a deviation of 3.2 for an alarm comparison.

0

ABS

Source

TempError

Dest

TempDeviation

SQRT — Square Root

Writes the square root of Source into Dest. A classic use is flow measurement: the differential pressure across an orifice plate grows with the square of the flow, so the flow signal is recovered with a square root.

0

SQRT

Source

PressureDrop

Dest

FlowRate

If Source is negative, SQRT takes the square root of its absolute value instead of failing — SQRT(-9.0) gives 3.0. This mirrors Logix 5000® controllers. It also means a sensor glitch below zero produces a plausible-looking number, so if a negative Source would be a fault in your process, check for it separately.

NEG — Negate

Flips the sign: 7 becomes -7, -2.5 becomes 2.5. Computed as 0 − Source, the same result you would get from SUB(0, Source, Dest).

0

NEG

Source

Offset

Dest

InvertedOffset

Rounding When Dest Is a DINT

Exactly like the two-source math instructions: the math itself can produce a fraction, and storing a fraction into a DINT destination rounds it — ties go to the nearest even number (banker rounding).

ExampleDest (DINT)Why
SQRT(3, DintDest)21.732… rounds up
SQRT(6.25, DintDest)22.5 is a tie — rounds to even
ABS(-2.5, DintDest)22.5 tie again
NEG(3.5, DintDest)-4−3.5 tie — even is −4

One Edge Case Worth Knowing

The most negative DINT, -2147483648, has no positive twin — the largest positive DINT is 2147483647. So ABS(-2147483648) and NEG(-2147483648) both give back -2147483648, still negative, with no error. Real controllers do the same. If a value can legitimately sit at that extreme, don't rely on ABS to make it positive.

On this page