com.github.kiprobinson.bigfraction
Enum DivisionMode

java.lang.Object
  extended by java.lang.Enum<DivisionMode>
      extended by com.github.kiprobinson.bigfraction.DivisionMode
All Implemented Interfaces:
Serializable, Comparable<DivisionMode>

public enum DivisionMode
extends Enum<DivisionMode>

Representation of methods of performing Euclidean division--dividing to an integer and obtaining a remainder. The division methods are all the same when dividend and divisor are positive, but they differ when one or both values are negative.

Given the division problem a/b, all methods produce integer quotient q and remainder r, with 0 <= r < b, fulfilling the equations:

a/b = q + r/b
a = b*q + r
r = a - b*q

More information available at https://en.wikipedia.org/wiki/Modulo_operation.


Enum Constant Summary
EUCLIDEAN
          Euclidean division chooses a quotient which will ensure that the remainder is always positive.
FLOORED
          In floored division, the quotient is floored (rounded toward negative infinity).
TRUNCATED
          In truncated division, the quotient is truncated (rounded toward zero).
 
Method Summary
static DivisionMode valueOf(String name)
          Returns the enum constant of this type with the specified name.
static DivisionMode[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

TRUNCATED

public static final DivisionMode TRUNCATED
In truncated division, the quotient is truncated (rounded toward zero). This is the method used by built-in % operator.

With this method, the remainder will have the same sign as the dividend (a).

q = trunc(a/b) (round toward zero)
r = a - b*q


FLOORED

public static final DivisionMode FLOORED
In floored division, the quotient is floored (rounded toward negative infinity).

With this method, the remainder will have the same sign as the divisor (b)

q = floor(a/b) (round toward negative infinity)
r = a - b*q


EUCLIDEAN

public static final DivisionMode EUCLIDEAN
Euclidean division chooses a quotient which will ensure that the remainder is always positive.

q = sign(b) * floor(a/abs(b))
Or:
b > 0: q = floor(a/b)
b < 0: q = ciel(a/b)

r = a - b*q

Method Detail

values

public static DivisionMode[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (DivisionMode c : DivisionMode.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static DivisionMode valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null