A trait that expresses the existence of signs and absolute values on linearly ordered additive commutative monoids (i.e. types with addition and a zero).
The following laws holds:
(1) if a <= b
then a + c <= b + c
(linear order),
(2) signum(x) = -1
if x < 0
, signum(x) = 1
if x > 0
, signum(x) = 0
otherwise,
Negative elements only appear when the scalar is taken from a additive abelian group. Then:
(3) abs(x) = -x
if x < 0
, or x
otherwise,
Laws (1) and (2) lead to the triange inequality:
(4) abs(a + b) <= abs(a) + abs(b)
Signed should never be extended in implementations, rather the Signed.forAdditiveCommutativeMonoid and subtraits.
It's better to have the Signed hierarchy separate from the Ring/Order hierarchy, so that we do not end up with duplicate implicits.
- Companion:
- object