trait Signed[A] extends Any
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.
- Source
- Signed.scala
- Alphabetic
- By Inheritance
- Signed
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def abs(a: A): A
An idempotent function that ensures an object has a non-negative sign.
- abstract def additiveCommutativeMonoid: AdditiveCommutativeMonoid[A]
- abstract def getClass(): Class[_ <: AnyRef]
- Definition Classes
- Any
- abstract def order: Order[A]
- abstract def signum(a: A): Int
Returns 0 if
a
is 0, 1 ifa
is positive, and -1 isa
is negative.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- Any
- final def ##: Int
- Definition Classes
- Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def equals(arg0: Any): Boolean
- Definition Classes
- Any
- def hashCode(): Int
- Definition Classes
- Any
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isSignNegative(a: A): Boolean
- def isSignNonNegative(a: A): Boolean
- def isSignNonPositive(a: A): Boolean
- def isSignNonZero(a: A): Boolean
- def isSignPositive(a: A): Boolean
- def isSignZero(a: A): Boolean
- def sign(a: A): Sign
Returns Zero if
a
is 0, Positive ifa
is positive, and Negative isa
is negative. - def toString(): String
- Definition Classes
- Any