Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E150 - ABS on a value of unsigned type has no effect

ABS returns the absolute value of its argument. A value of an unsigned type cannot be negative, so ABS returns the argument unchanged. Such a call usually points at a mistake, for example an argument expression that already underflowed:

FUNCTION delta : UINT
VAR_INPUT
    a, b : UINT;
END_VAR
    // WRONG: a - b underflows for a < b, ABS does not correct the result
    delta := ABS(a - b);
END_FUNCTION

If the distance between two unsigned values is needed, compare them first:

IF a >= b THEN
    delta := a - b;
ELSE
    delta := b - a;
END_IF