public class Rational
extends java.lang.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(java.lang.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.
|
java.lang.String |
toDescriptiveString() |
java.lang.String |
toString() |
static Rational |
valueOf(java.math.BigInteger num,
java.math.BigInteger den) |
static Rational |
valueOf(double d) |
static Rational |
valueOf(long num,
long den) |
static Rational |
valueOf(java.lang.String str)
Parses a string.
|
public 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 java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toDescriptiveString()
public int intValue()
intValue
in class java.lang.Number
public long longValue()
longValue
in class java.lang.Number
public float floatValue()
floatValue
in class java.lang.Number
public double doubleValue()
doubleValue
in class java.lang.Number
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int compareTo(Rational that)
public int hashCode()
hashCode
in class java.lang.Object
public boolean isZero()
public boolean isLessOrEqualZero()
public static Rational valueOf(double d)
public static Rational valueOf(long num, long den)
public static Rational valueOf(java.math.BigInteger num, java.math.BigInteger den)
public Rational round(long d)
public static Rational valueOf(java.lang.String str)
java.lang.NumberFormatException
- if str can not be parsed.