trait TruncatedDivision[A] extends Signed[A]

Division and modulus for computer scientists taken from https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf

For two numbers x (dividend) and y (divisor) on an ordered ring with y != 0, there exists a pair of numbers q (quotient) and r (remainder) such that these laws are satisfied:

(1) q is an integer (2) x = y * q + r (division rule) (3) |r| < |y|, (4t) r = 0 or sign(r) = sign(x), (4f) r = 0 or sign(r) = sign(y).

where sign is the sign function, and the absolute value function |x| is defined as |x| = x if x >=0, and |x| = -x otherwise.

We define functions tmod and tquot such that: q = tquot(x, y) and r = tmod(x, y) obey rule (4t), (which truncates effectively towards zero) and functions fmod and fquot such that: q = fquot(x, y) and r = fmod(x, y) obey rule (4f) (which floors the quotient and effectively rounds towards negative infinity).

Law (4t) corresponds to ISO C99 and Haskell's quot/rem. Law (4f) is described by Knuth and used by Haskell, and fmod corresponds to the REM function of the IEEE floating-point standard.

Source
TruncatedDivision.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. TruncatedDivision
  2. Signed
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Abstract Value Members

  1. abstract 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.

    Definition Classes
    Signed
  2. abstract def additiveCommutativeMonoid: AdditiveCommutativeMonoid[A]
    Definition Classes
    Signed
  3. abstract def fmod(x: A, y: A): A
  4. abstract def fquot(x: A, y: A): A
  5. abstract def getClass(): Class[_ <: AnyRef]
    Definition Classes
    Any
  6. abstract def order: Order[A]
    Definition Classes
    Signed
  7. abstract 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.

    Definition Classes
    Signed
  8. abstract def tmod(x: A, y: A): A
  9. abstract def tquot(x: A, y: A): A

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    Any
  2. final def ##: Int
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def equals(arg0: Any): Boolean
    Definition Classes
    Any
  6. def fquotmod(x: A, y: A): (A, A)
  7. def hashCode(): Int
    Definition Classes
    Any
  8. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  9. def isSignNegative(a: A): Boolean
    Definition Classes
    Signed
  10. def isSignNonNegative(a: A): Boolean
    Definition Classes
    Signed
  11. def isSignNonPositive(a: A): Boolean
    Definition Classes
    Signed
  12. def isSignNonZero(a: A): Boolean
    Definition Classes
    Signed
  13. def isSignPositive(a: A): Boolean
    Definition Classes
    Signed
  14. def isSignZero(a: A): Boolean
    Definition Classes
    Signed
  15. 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.

    Definition Classes
    Signed
  16. def toString(): String
    Definition Classes
    Any
  17. def tquotmod(x: A, y: A): (A, A)

Inherited from Signed[A]

Inherited from Any

Ungrouped