/Prelude-v22.0.0/Integer/abs.dhall

Copy path to clipboard

Returns the absolute value of an Integer, i.e. its non-negative value.

Examples

abs +7 ≡ 7
abs +0 ≡ 0
abs -3 ≡ 3

Source

--| Returns the absolute value of an `Integer`, i.e. its non-negative value.
let abs
: Integer → Natural
= λ(n : Integer) →
if Natural/isZero (Integer/clamp n)
then Integer/clamp (Integer/negate n)
else Integer/clamp n

let example0 = assert : abs +7 ≡ 7

let example2 = assert : abs +0 ≡ 0

let example3 = assert : abs -3 ≡ 3

in abs