Absolute valueΒΆ
The absolute value function applied to a number x
can be written
either abs(x)
or using the traditional notation |x|
.
Disco> abs(6)
6
Disco> abs(-6)
6
Disco> abs(-1/2)
1/2
Disco> |-6|
6
Since the output of abs
is always positive, it can convert
rational numbers into fractional numbers,
and integers into natural numbers.
The notation |~|
can also be used to find the size
of a collection such as a set, bag, or
list.