java.io.Serializable, java.lang.Comparable<LongFraction>public class LongFraction extends java.lang.Number implements java.lang.Comparable<LongFraction>
longs.
The value of the fraction is always kept reduced to the lowest possible terms.
| Modifier and Type | Field | Description |
|---|---|---|
static LongFraction |
ONE |
Fraction of
1/1. |
static LongFraction |
ONE_HALF |
Fraction of
1/2. |
static LongFraction |
ONE_QUARTER |
Fraction of
1/4. |
static LongFraction |
ONE_THIRD |
Fraction of
1/3. |
static LongFraction |
THREE_QUARTERS |
Fraction of
3/4. |
static LongFraction |
TWO_THIRDS |
Fraction of
2/3. |
static LongFraction |
ZERO |
Fraction of
0/1. |
| Modifier and Type | Method | Description |
|---|---|---|
LongFraction |
abs() |
Returns the absolute value of this fraction.
|
LongFraction |
add(long value) |
Returns the sum of this fraction and the given number.
|
LongFraction |
add(LongFraction other) |
Returns the sum of this fraction and the given fraction.
|
int |
compareTo(LongFraction other) |
|
LongFraction |
divide(long value) |
Returns the quotient of this fraction and the given number.
|
LongFraction |
divide(LongFraction other) |
Returns the quotient of this fraction and the given fraction.
|
double |
doubleValue() |
|
boolean |
equals(java.lang.Object other) |
|
float |
floatValue() |
|
long |
getDenominator() |
Returns the denominator of this fraction.
|
long |
getNumerator() |
Returns the numerator of this fraction.
|
int |
hashCode() |
|
int |
intValue() |
|
int |
intValueExact() |
Returns the
int value of this fraction. |
boolean |
isInteger() |
Checks whether the value of this fraction is an integer.
|
long |
longValue() |
|
long |
longValueExact() |
Returns the
long value of this fraction. |
LongFraction |
multiply(long value) |
Returns the product of this fraction and the given number.
|
LongFraction |
multiply(LongFraction other) |
Returns the product of this fraction and the given fraction.
|
LongFraction |
negate() |
Returns the opposite of this fraction.
|
static LongFraction |
parse(java.lang.String text) |
Returns a fraction obtained from the given text string.
|
LongFraction |
pow(int exponent) |
Returns this fraction raised to the power of the given exponent.
|
LongFraction |
reciprocal() |
Return the reciprocal of this fraction.
|
long |
round(java.math.RoundingMode roundingMode) |
Returns the integer value nearest to the value of this fraction.
|
int |
signum() |
Returns the signum of this value.
|
LongFraction |
subtract(long value) |
Returns the difference of this fraction and the given number.
|
LongFraction |
subtract(LongFraction other) |
Returns the difference of this fraction and the given fraction.
|
java.math.BigDecimal |
toBigDecimal() |
Returns the
BigDecimal value of this fraction. |
java.math.BigDecimal |
toBigDecimal(int scale,
java.math.RoundingMode roundingMode) |
Returns the
BigDecimal value of this fraction. |
java.lang.String |
toString() |
|
static LongFraction |
valueOf(long value) |
Returns a fraction with the given value.
|
static LongFraction |
valueOf(long numerator,
long denominator) |
Returns a fraction with the given numerator and denominator.
|
public static final LongFraction ONE
1/1.public static final LongFraction ONE_HALF
1/2.public static final LongFraction ONE_QUARTER
1/4.public static final LongFraction ONE_THIRD
1/3.public static final LongFraction THREE_QUARTERS
3/4.public static final LongFraction TWO_THIRDS
2/3.public static final LongFraction ZERO
0/1.public LongFraction abs()
java.lang.ArithmeticException - if numerator is equal to Integer.MIN_VALUEpublic LongFraction add(long value)
public LongFraction add(LongFraction other)
java.lang.IllegalArgumentException - if other is nullpublic int compareTo(LongFraction other)
compareTo in interface java.lang.Comparable<LongFraction>public LongFraction divide(long value)
java.lang.ArithmeticException - if value is equal to 0public LongFraction divide(LongFraction other)
java.lang.ArithmeticException - if other is equal to 0public double doubleValue()
doubleValue in class java.lang.Numberpublic boolean equals(java.lang.Object other)
equals in class java.lang.Objectpublic float floatValue()
floatValue in class java.lang.Numberpublic long getDenominator()
public long getNumerator()
public int hashCode()
hashCode in class java.lang.Objectpublic int intValue()
intValue in class java.lang.Numberpublic boolean isInteger()
public int intValueExact()
int value of this fraction.java.lang.IllegalArgumentException - if the value of this fraction does not exactly fit an intpublic long longValue()
longValue in class java.lang.Numberpublic long longValueExact()
long value of this fraction.java.lang.IllegalArgumentException - if the value of this fraction does not exactly fit a longpublic LongFraction multiply(long value)
public LongFraction multiply(LongFraction other)
java.lang.IllegalArgumentException - if other is nullpublic LongFraction negate()
java.lang.ArithmeticException - if numerator is equal to Integer.MIN_VALUEpublic static LongFraction parse(java.lang.String text)
java.lang.IllegalArgumentException - if text is nulljava.lang.NumberFormatException - if text is not a valid fractionpublic LongFraction pow(int exponent)
public LongFraction reciprocal()
java.lang.ArithmeticException - if the value of this fraction is equal to 0public long round(java.math.RoundingMode roundingMode)
java.lang.IllegalArgumentException - if roundingMode is nullpublic int signum()
public LongFraction subtract(long value)
public LongFraction subtract(LongFraction other)
java.lang.IllegalArgumentException - if other is nullpublic java.math.BigDecimal toBigDecimal()
BigDecimal value of this fraction.java.lang.IllegalArgumentException - if the value of this fraction does not have a terminating decimal expansionpublic java.math.BigDecimal toBigDecimal(int scale,
java.math.RoundingMode roundingMode)
BigDecimal value of this fraction.java.lang.IllegalArgumentException - if roundingMode is nullpublic java.lang.String toString()
toString in class java.lang.Objectpublic static LongFraction valueOf(long value)
public static LongFraction valueOf(long numerator, long denominator)
java.lang.IllegalArgumentException - if denominator is 0