public class Rational extends Object
BigIntegers.| Constructor and Description |
|---|
Rational(BigInteger p,
BigInteger q)
Creates a rational number p/q with the numerator p and the
denominator q.
|
Rational(long p,
long q)
Creates a rational number p/q with the numerator p and the
denominator q.
|
| Modifier and Type | Method and Description |
|---|---|
Rational |
add(Rational n)
Returns the rational number k = m + n where
m is this rational number.
|
static BigInteger[] |
cancel(BigInteger p,
BigInteger q)
Returns a two-element array representing the fraction p/q
where all common factors of numerator and denominator are cancelled.
|
Rational |
divide(BigInteger n)
Returns the rational number k = m/n where
m is this rational number.
|
Rational |
divide(long n)
Returns the rational number k = m/n where
m is this rational number.
|
Rational |
divide(Rational n)
Returns the rational number k = m/n where
m is this rational number.
|
Rational |
minus(Rational n)
Returns the rational number k = m - n where
m is this rational number.
|
Rational |
multiply(BigInteger n)
Returns the rational number k = mn where
m is this rational number.
|
Rational |
multiply(Rational n)
Returns the rational number k = mn where
m is this rational number.
|
Rational |
negate()
Returns the negative of this rational number.
|
Rational |
plus(Rational n)
Returns the rational number k = m + n where
m is this rational number.
|
Rational |
reciprocal()
Returns the reciprocal 1/n of this rational n.
|
Rational |
subtract(Rational n)
Returns the rational number k = m - n where
m is this rational number.
|
String |
toString()
Returns a string representation of this rational number.
|
public Rational(long p,
long q)
0
and q = 1.p - the numeratorq - the denominatorpublic Rational(BigInteger p, BigInteger q)
0
and q = 1.p - the numeratorq - the denominatorpublic Rational add(Rational n)
n - the summandthis + nplus(Rational)public static BigInteger[] cancel(BigInteger p, BigInteger q)
p - the numeratorq - the denominatorpublic Rational divide(Rational n)
n - the divisorthis / ndivide(BigInteger),
divide(long)public Rational divide(BigInteger n)
n - the divisorthis / ndivide(Rational),
divide(long)public Rational divide(long n)
n - the divisorthis / ndivide(Rational),
divide(BigInteger)public Rational minus(Rational n)
n - the subtrahendthis - npublic Rational multiply(Rational n)
n - the factorthis * npublic Rational multiply(BigInteger n)
n - the factorthis * npublic Rational negate()
thispublic Rational plus(Rational n)
n - the summandthis + npublic Rational reciprocal()
public Rational subtract(Rational n)
n - the subtrahendthis - nminus(Rational)