Signed

algebra.ring.Signed
See theSigned companion object
trait Signed[A]

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.

Attributes

Companion
object
Source
Signed.scala
Graph
Supertypes
class Any
Known subtypes

Members list

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.

Attributes

Source
Signed.scala
def order: Order[A]

Attributes

Source
Signed.scala
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.

Attributes

Source
Signed.scala

Concrete methods

Attributes

Source
Signed.scala

Attributes

Source
Signed.scala

Attributes

Source
Signed.scala

Attributes

Source
Signed.scala

Attributes

Source
Signed.scala
def isSignZero(a: A): Boolean

Attributes

Source
Signed.scala
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.

Attributes

Source
Signed.scala