Abs

Syntax:

    integer_variable = Abs( integer_variable )

Command Availability:

Available on all microcontrollers.

Explanation:

The Abs function computes the absolute value of an integer number, in the range -32767 to +32767.

Example:

    absolute_value = Abs( -127 )  ' Will return 127          ' <<< the Abs instruction
    absolute_value = Abs( 127 )   ' Will return 127 also

Key line: Abs( -127 ) — strips the sign from a negative value, returning 127 either way, regardless of whether the input was positive or negative.

See Also:

  • Average — related command in the same category
  • Difference — related command in the same category