java.io.Serializable, java.lang.Comparable<BigFraction>public class BigFraction extends java.lang.Number implements java.lang.Comparable<BigFraction>
BigIntegers.
The value of the fraction is always kept reduced to the lowest possible terms.
| Modifier and Type | Field | Description |
|---|---|---|
static BigFraction |
ONE |
Fraction of
1/1. |
static BigFraction |
ONE_HALF |
Fraction of
1/2. |
static BigFraction |
ONE_QUARTER |
Fraction of
1/4. |
static BigFraction |
ONE_THIRD |
Fraction of
1/3. |
static BigFraction |
THREE_QUARTERS |
Fraction of
3/4. |
static BigFraction |
TWO_THIRDS |
Fraction of
2/3. |
static BigFraction |
ZERO |
Fraction of
0/1. |
| Modifier and Type | Method | Description |
|---|---|---|
BigFraction |
abs() |
Returns the absolute value of this fraction.
|
BigFraction |
add(long value) |
Returns the sum of this fraction and the given number.
|
BigFraction |
add(java.math.BigInteger value) |
Returns the sum of this fraction and the given number.
|
BigFraction |
add(BigFraction other) |
Returns the sum of this fraction and the given fraction.
|
int |
compareTo(BigFraction other) |
|
BigFraction |
divide(long value) |
Returns the quotient of this fraction and the given number.
|
BigFraction |
divide(java.math.BigInteger value) |
Returns the quotient of this fraction and the given number.
|
BigFraction |
divide(BigFraction other) |
Returns the quotient of this fraction and the given fraction.
|
double |
doubleValue() |
|
boolean |
equals(java.lang.Object other) |
|
float |
floatValue() |
|
java.math.BigInteger |
getDenominator() |
Returns the denominator of this fraction.
|
java.math.BigInteger |
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. |
BigFraction |
multiply(long value) |
Returns the product of this fraction and the given number.
|
BigFraction |
multiply(java.math.BigInteger value) |
Returns the product of this fraction and the given number.
|
BigFraction |
multiply(BigFraction other) |
Returns the product of this fraction and the given fraction.
|
BigFraction |
negate() |
Returns the opposite of this fraction.
|
static BigFraction |
parse(java.lang.String text) |
Returns a fraction obtained from the given text string.
|
BigFraction |
pow(int exponent) |
Returns this fraction raised to the power of the given exponent.
|
BigFraction |
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.
|
BigFraction |
subtract(long value) |
Returns the difference of this fraction and the given number.
|
BigFraction |
subtract(java.math.BigInteger value) |
Returns the difference of this fraction and the given number.
|
BigFraction |
subtract(BigFraction 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 BigFraction |
valueOf(long value) |
Returns a fraction with the given value.
|
static BigFraction |
valueOf(long numerator,
long denominator) |
Returns a fraction with the given numerator and denominator.
|
static BigFraction |
valueOf(java.math.BigInteger value) |
Returns a fraction with the given value.
|
static BigFraction |
valueOf(java.math.BigInteger numerator,
java.math.BigInteger denominator) |
Returns a fraction with the given numerator and denominator.
|
public static final BigFraction ONE
1/1.public static final BigFraction ONE_HALF
1/2.public static final BigFraction ONE_QUARTER
1/4.public static final BigFraction ONE_THIRD
1/3.public static final BigFraction THREE_QUARTERS
3/4.public static final BigFraction TWO_THIRDS
2/3.public static final BigFraction ZERO
0/1.public BigFraction abs()
java.lang.ArithmeticException - if numerator is equal to Integer.MIN_VALUEpublic BigFraction add(BigFraction other)
java.lang.IllegalArgumentException - if other is nullpublic BigFraction add(java.math.BigInteger value)
java.lang.IllegalArgumentException - if value is nullpublic BigFraction add(long value)
public int compareTo(BigFraction other)
compareTo in interface java.lang.Comparable<BigFraction>public BigFraction divide(BigFraction other)
java.lang.ArithmeticException - if other is equal to 0public BigFraction divide(java.math.BigInteger value)
java.lang.ArithmeticException - if value is equal to 0java.lang.IllegalArgumentException - if value is nullpublic BigFraction divide(long value)
java.lang.ArithmeticException - if value 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 java.math.BigInteger getDenominator()
public java.math.BigInteger 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 BigFraction multiply(BigFraction other)
java.lang.IllegalArgumentException - if other is nullpublic BigFraction multiply(java.math.BigInteger value)
java.lang.IllegalArgumentException - if value is nullpublic BigFraction multiply(long value)
public BigFraction negate()
java.lang.ArithmeticException - if numerator is equal to Integer.MIN_VALUEpublic static BigFraction parse(java.lang.String text)
java.lang.IllegalArgumentException - if text is nulljava.lang.NumberFormatException - if text is not a valid fractionpublic BigFraction pow(int exponent)
public BigFraction 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 BigFraction subtract(BigFraction other)
java.lang.IllegalArgumentException - if other is nullpublic BigFraction subtract(java.math.BigInteger value)
java.lang.IllegalArgumentException - if value is nullpublic BigFraction subtract(long value)
public 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 BigFraction valueOf(java.math.BigInteger value)
java.lang.IllegalArgumentException - if value is nullpublic static BigFraction valueOf(java.math.BigInteger numerator, java.math.BigInteger denominator)
java.lang.IllegalArgumentException - if denominator is nulljava.lang.IllegalArgumentException - if denominator is 0java.lang.IllegalArgumentException - if numerator is nullpublic static BigFraction valueOf(long value)
public static BigFraction valueOf(long numerator, long denominator)
java.lang.IllegalArgumentException - if denominator is 0