dividend/divisor with dividend
and divisor being integer numbers.
Implementation Specification
This implementation uses BigInteger to represent 'dividend' and
'divisor'.
| Modifier and Type | Field and Description |
|---|---|
| private final Object | |
| private final Object | |
| private final BigInteger | |
| private final BigInteger | |
| public static char | DIVISION_CHARACTER
The default |
| private transient BigDecimal | |
| private final int | |
| private final boolean | |
| private transient Long | |
| public static final RationalNumber | |
| private static final long | |
| private final int | |
| public static final RationalNumber |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public RationalNumber | Returns: abs(this)Returns a |
| public RationalNumber | Returns: this + thatReturns a new instance of |
| public BigDecimal | |
| public int | Returns: the value0 if this equals (numerically)
that; a value less than 0 if this < that; and
a value greater than 0 if this > thatCompares two |
| public RationalNumber | Returns: this / thatReturns a new instance of |
| public double | doubleValue()
Implements abstract java. Returns the value of the specified number as a |
| public boolean | Returns: true if and only if the specified Object is a
RationalNumber whose value is numerically equal to this RationalNumber.Object to which this RationalNumber is to be compared. x)Overrides java. Compares this RationalNumber with the specified Object for equality. |
| public float | floatValue()
Implements abstract java. Returns the value of the specified number as a |
| public BigInteger | Returns: sign(a/b) * abs(a), (given rational number a/b)For a non-negative rational number, returns a non-negative dividend. |
| public BigInteger | Returns: abs(b), (given rational number a/b)By convention, returns a non-negative divisor. |
| public int | |
| public int | intValue()
Implements abstract java. Returns the value of the specified number as an |
| public boolean | |
| private String | Returns: string with canonical string representation of thisRationalNumbertrue for fractional representation 5÷3;
false for decimal 1.66667.Lay out this |
| public long | longValue()
Implements abstract java. Returns the value of the specified number as a |
| public RationalNumber | Returns: this * thatReturns a new instance of |
| public RationalNumber | |
| public static RationalNumber | Returns: dividend/divisorReturns a |
| public static RationalNumber | of(double number)
Returns a |
| public static RationalNumber | of(BigDecimal decimalValue)
Returns a |
| public static RationalNumber | Returns: dividend/divisorthe dividend dividend, BigInteger the divisor divisor)Returns a |
| public static RationalNumber | |
| public static RationalNumber | |
| public RationalNumber | Returns: this^exponentReturns a new instance of |
| public RationalNumber | Returns: 1/thisReturns a new instance of |
| public int | |
| public RationalNumber | Returns: this - thatReturns a new instance of |
| public String | Returns: string representation of thisRationalNumber, using
fractional notation.Returns a string representation of this |
| public String | Returns: string representation of thisRationalNumber, using
fractional notation.the character to use instead of the default divisionCharacter)÷Returns a string representation of this |
| public String |
| $lock1 | back to summary |
|---|---|
| private final Object $lock1 | |
| $lock2 | back to summary |
|---|---|
| private final Object $lock2 | |
| absDividend | back to summary |
|---|---|
| private final BigInteger absDividend | |
| absDivisor | back to summary |
|---|---|
| private final BigInteger absDivisor | |
| DIVISION_CHARACTER | back to summary |
|---|---|
| public static char DIVISION_CHARACTER The default Note Number parsing will fail if this is a white-space character. | |
| divisionResult | back to summary |
|---|---|
| private transient BigDecimal divisionResult | |
| hashCode | back to summary |
|---|---|
| private final int hashCode | |
| isInteger | back to summary |
|---|---|
| private final boolean isInteger | |
| longValue | back to summary |
|---|---|
| private transient Long longValue | |
| ONE | back to summary |
|---|---|
| public static final RationalNumber ONE | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| signum | back to summary |
|---|---|
| private final int signum | |
| ZERO | back to summary |
|---|---|
| public static final RationalNumber ZERO | |
| RationalNumber | back to summary |
|---|---|
| private RationalNumber(int signum, BigInteger absDividend, BigInteger absDivisor) | |
| abs | back to summary |
|---|---|
| public RationalNumber abs() Returns a
| |
| add | back to summary |
|---|---|
| public RationalNumber add(RationalNumber that) Returns a new instance of
| |
| bigDecimalValue | back to summary |
|---|---|
| public BigDecimal bigDecimalValue() The
| |
| compareTo | back to summary |
|---|---|
| public int compareTo(RationalNumber that) Compares two
| |
| divide | back to summary |
|---|---|
| public RationalNumber divide(RationalNumber that) Returns a new instance of
| |
| doubleValue | back to summary |
|---|---|
| public double doubleValue() Implements abstract java. Doc from java. Returns the value of the specified number as a
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object x) Overrides java. Compares this RationalNumber with the specified Object for equality. | |
| floatValue | back to summary |
|---|---|
| public float floatValue() Implements abstract java. Doc from java. Returns the value of the specified number as a
| |
| getDividend | back to summary |
|---|---|
| public BigInteger getDividend() For a non-negative rational number, returns a non-negative dividend.
Otherwise returns a negative dividend. In other words, by convention,
the integer returned includes the sign of this
| |
| getDivisor | back to summary |
|---|---|
| public BigInteger getDivisor() By convention, returns a non-negative divisor.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| intValue | back to summary |
|---|---|
| public int intValue() Implements abstract java. Doc from java. Returns the value of the specified number as an
| |
| isInteger | back to summary |
|---|---|
public boolean isInteger()
| |
| layoutChars | back to summary |
|---|---|
| private String layoutChars(boolean useFractionalRepresentation, char divisionCharacter) Lay out this
| |
| longValue | back to summary |
|---|---|
| public long longValue() Implements abstract java. Doc from java. Returns the value of the specified number as a
| |
| multiply | back to summary |
|---|---|
| public RationalNumber multiply(RationalNumber that) Returns a new instance of
| |
| negate | back to summary |
|---|---|
| public RationalNumber negate() Returns a new instance of
| |
| of | back to summary |
|---|---|
| public static RationalNumber of(long dividend, long divisor) Returns a
| |
| of | back to summary |
|---|---|
| public static RationalNumber of(double number) Returns a | |
| of | back to summary |
|---|---|
| public static RationalNumber of(BigDecimal decimalValue) Returns a | |
| of | back to summary |
|---|---|
| public static RationalNumber of(BigInteger dividend, BigInteger divisor) Returns a
| |
| ofInteger | back to summary |
|---|---|
| public static RationalNumber ofInteger(long number) Returns a
| |
| ofInteger | back to summary |
|---|---|
| public static RationalNumber ofInteger(BigInteger number) Returns a
| |
| pow | back to summary |
|---|---|
| public RationalNumber pow(int exponent) Returns a new instance of
| |
| reciprocal | back to summary |
|---|---|
| public RationalNumber reciprocal() Returns a new instance of
| |
| signum | back to summary |
|---|---|
public int signum()
| |
| subtract | back to summary |
|---|---|
| public RationalNumber subtract(RationalNumber that) Returns a new instance of
| |
| toRationalString | back to summary |
|---|---|
| public String toRationalString() Returns a string representation of this
| |
| toRationalString | back to summary |
|---|---|
| public String toRationalString(char divisionCharacter) Returns a string representation of this
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |