Signed

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
class Any

Value members

Abstract methods

def abs(a: A): A

An idempotent function that ensures an object has a non-negative sign.

An idempotent function that ensures an object has a non-negative sign.

def order: Order[A]
def signum(a: A): Int

Returns 0 if a is 0, 1 if a is positive, and -1 is a is negative.

Returns 0 if a is 0, 1 if a is positive, and -1 is a is negative.

Concrete methods

def isSignZero(a: A): Boolean
def sign(a: A): Sign

Returns Zero if a is 0, Positive if a is positive, and Negative is a is negative.

Returns Zero if a is 0, Positive if a is positive, and Negative is a is negative.