Matchbox 0.2

abs

Return the absolute value of an integer. A negative input becomes positive, while zero and positive inputs are returned unchanged.

Signature

func abs(num int) int

Parameters

  • num — the integer whose absolute value is required.

Return Value

The non-negative absolute value of num.

Example

var distance = abs(-12)
print(distance)

The example writes 12 to standard output.

The absolute value of -2,147,483,648 cannot be represented by int and is not defined by 0.2.