public class BigFraction
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static BigFraction |
ONE |
static BigFraction |
ZERO |
Constructor and Description |
---|
BigFraction(BigFraction f)
Given a BigFraction, copy its BigInteger numerator and denominator fields to the fields of the new BigFraction object.
|
BigFraction(java.math.BigInteger numerator,
java.math.BigInteger denominator)
Given a BigInteger numerator and denominator, simplify the fraction by dividing both numerator and denominator by their greatest common divisor, and
change signs such that the denominator is always positive.
|
BigFraction(long numerator,
long denominator)
Construct a BigFraction given two long numerator and denominator values, convert and assign them to BigInteger numerator and denominator values.
|
BigFraction(java.lang.String s)
Given a String consisting of two integers separated by a single '/', initialize the numerator and denominator fields
with BigIntegers constructed with the substrings before and after the '/', respectively.
|
Modifier and Type | Method and Description |
---|---|
BigFraction |
add(BigFraction b)
Return a BigFraction resulting from the addition of a given BigFraction b to this BigFraction.
|
java.math.BigDecimal |
asBigDecimal(int scale,
java.math.RoundingMode roundingMode)
Return a BigDecimal formed by converting the BigInteger numerator and denominator to BigDecimals and then
dividing the BigDecimal numerator by the BigDecimal denominator using the given scale and rounding mode.
|
BigFraction |
divide(BigFraction b)
Return a BigFraction resulting from the division of a given BigFraction b into this BigFraction.
|
java.math.BigInteger |
getDen()
Return the BigInteger denominator of the BigFraction.
|
java.math.BigInteger |
getNum()
Return the BigInteger numerator of the BigFraction.
|
BigFraction |
multiply(BigFraction b)
Return a BigFraction resulting from the multiplication of a given BigFraction b with this BigFraction.
|
BigFraction |
negate()
Return a new BigFraction object with the same denominator and the negated numerator.
|
BigFraction |
subtract(BigFraction b)
Return a BigFraction resulting from the subtraction of a given BigFraction b from this BigFraction.
|
java.lang.String |
toString()
Return a String consisting of the numerator and denominator separated by a single '/'.
|
public static final BigFraction ONE
public static final BigFraction ZERO
public BigFraction(java.math.BigInteger numerator, java.math.BigInteger denominator)
numerator
- BigInteger numerator of the BigFractiondenominator
- BigInteger denominator of the BigFractionpublic BigFraction(BigFraction f)
f
- given BigFraction object to copy in this constructorpublic BigFraction(java.lang.String s)
s
- a String representation of a fraction consisting of two integers separated by a single '/'public BigFraction(long numerator, long denominator)
numerator
- given long numerator valuedenominator
- given long denominator valuepublic java.math.BigInteger getNum()
public java.math.BigInteger getDen()
public java.lang.String toString()
toString
in class java.lang.Object
public java.math.BigDecimal asBigDecimal(int scale, java.math.RoundingMode roundingMode)
scale
- the number of decimal places for the division computationroundingMode
- rounding mode for determining the correct final digit of the division result at the given scalepublic BigFraction negate()
public BigFraction add(BigFraction b)
b
- given BigFraction to add to this BigFractionpublic BigFraction subtract(BigFraction b)
b
- given BigFraction to subtract from this BigFractionpublic BigFraction multiply(BigFraction b)
b
- given BigFraction to multiply with this BigFractionpublic BigFraction divide(BigFraction b)
b
- given BigFraction to divide into this BigFraction