public class Rational extends Number
Two LONGs 32-bit (4-byte) unsigned integer: the first represents the numerator of a fraction; the second, the denominator.
Invariants:
| Modifier and Type | Field and Description |
|---|---|
static Rational |
ONE |
static long |
serialVersionUID |
static Rational |
ZERO |
| Constructor and Description |
|---|
Rational(long numerator) |
Rational(long numerator,
long denominator) |
Rational(Rational r) |
| Modifier and Type | Method and Description |
|---|---|
Rational |
add(Rational that) |
Rational |
ceil(long d)
Returns the closest rational with the specified denominator which is
greater or equal than this number.
|
int |
compareTo(Rational that)
return { -1, 0, +1 } if a < b, a = b, or a > b.
|
Rational |
divide(Rational that) |
double |
doubleValue() |
boolean |
equals(Object obj) |
float |
floatValue() |
Rational |
floor(long d)
Returns the closest rational with the specified denominator which is
smaller or equal than this number.
|
long |
getDenominator() |
long |
getNumerator() |
int |
hashCode() |
int |
intValue() |
Rational |
inverse() |
boolean |
isLessOrEqualZero() |
boolean |
isZero() |
long |
longValue() |
static Rational |
max(Rational a,
Rational b) |
static Rational |
min(Rational a,
Rational b) |
Rational |
multiply(long integer) |
Rational |
multiply(Rational that) |
Rational |
negate() |
Rational |
round(long d) |
Rational |
subtract(Rational that)
Warning.
|
String |
toDescriptiveString() |
String |
toString() |
static Rational |
valueOf(BigInteger num,
BigInteger den) |
static Rational |
valueOf(double d) |
static Rational |
valueOf(long num,
long den) |
static Rational |
valueOf(String str)
Parses a string.
|
byteValue, shortValuepublic static final Rational ONE
public static final Rational ZERO
public static final long serialVersionUID
public Rational(long numerator)
public Rational(long numerator,
long denominator)
public Rational(Rational r)
public long getNumerator()
public long getDenominator()
public Rational subtract(Rational that)
public Rational negate()
public Rational inverse()
public Rational floor(long d)
public Rational ceil(long d)
public Rational multiply(long integer)
public String toDescriptiveString()
public float floatValue()
floatValue in class Numberpublic double doubleValue()
doubleValue in class Numberpublic int compareTo(Rational that)
public boolean isZero()
public boolean isLessOrEqualZero()
public static Rational valueOf(double d)
public static Rational valueOf(long num, long den)
public static Rational valueOf(BigInteger num, BigInteger den)
public Rational round(long d)
public static Rational valueOf(String str)
NumberFormatException - if str can not be parsed.Copyright © 2014. All Rights Reserved.