|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rit.numeric.Rational
public class Rational
Class Rational provides a 32-bit rational number. A 32-bit rational number is the ratio of two 32-bit integers (type int). Operations are provided for exact arithmetic and comparison with rational numbers.
Class Rational overrides the equals() and hashCode()
methods, making it suitable for use as a key in a hashed data structure like
a HashMap or HashSet. However, a Rational object is mutable. Take care not
to change the value of a Rational object if it is used as a key in a hashed
data structure.
Class Rational is not multiple thread safe.
| Constructor Summary | |
|---|---|
Rational()
Construct a new rational number. |
|
Rational(int value)
Construct a new rational number. |
|
Rational(int numer,
int denom)
Construct a new rational number. |
|
Rational(Rational value)
Construct a new rational number. |
|
Rational(String s)
Construct a new rational number. |
|
| Method Summary | |
|---|---|
Rational |
abs(int x)
Set this rational number to the absolute value of the given number. |
Rational |
abs(Rational x)
Set this rational number to the absolute value of the given number. |
Rational |
add(int x,
int y)
Set this rational number to the sum of the given numbers. |
Rational |
add(int x,
Rational y)
Set this rational number to the sum of the given numbers. |
Rational |
add(Rational x,
int y)
Set this rational number to the sum of the given numbers. |
Rational |
add(Rational x,
Rational y)
Set this rational number to the sum of the given numbers. |
Rational |
assign(int x)
Set this rational number to the given number. |
Rational |
assign(Rational x)
Set this rational number to the given number. |
Rational |
assign(String s)
Set this rational number to the value parsed from the given string. |
int |
compareTo(Object obj)
Compare this rational number to the given object. |
Rational |
div(int x,
int y)
Set this rational number to the quotient of the given numbers. |
Rational |
div(int x,
Rational y)
Set this rational number to the quotient of the given numbers. |
Rational |
div(Rational x,
int y)
Set this rational number to the quotient of the given numbers. |
Rational |
div(Rational x,
Rational y)
Set this rational number to the quotient of the given numbers. |
double |
doubleValue()
Converts this rational number to a double precision floating point number. |
boolean |
eq(int x)
Determine if this rational number is equal to the given number. |
boolean |
eq(Rational x)
Determine if this rational number is equal to the given number. |
boolean |
equals(Object obj)
Determine if this rational number is equal to the given object. |
boolean |
eqZero()
Determine if this rational number is equal to zero. |
float |
floatValue()
Converts this rational number to a single precision floating point number. |
Rational |
fracPart(Rational x)
Set this rational number to the fractional part of the given rational number. |
boolean |
ge(int x)
Determine if this rational number is greater than or equal to the given number. |
boolean |
ge(Rational x)
Determine if this rational number is greater than or equal to the given number. |
boolean |
geZero()
Determine if this rational number is greater than or equal to zero. |
boolean |
gt(int x)
Determine if this rational number is greater than the given number. |
boolean |
gt(Rational x)
Determine if this rational number is greater than the given number. |
boolean |
gtZero()
Determine if this rational number is greater than zero. |
int |
hashCode()
Returns a hash code for this rational number. |
Rational |
intPart(Rational x)
Set this rational number to the integer part of the given rational number. |
int |
intValue()
Converts this rational number to an integer. |
boolean |
le(int x)
Determine if this rational number is less than or equal to the given number. |
boolean |
le(Rational x)
Determine if this rational number is less than or equal to the given number. |
boolean |
leZero()
Determine if this rational number is less than or equal to zero. |
long |
longValue()
Converts this rational number to a long integer. |
boolean |
lt(int x)
Determine if this rational number is less than the given number. |
boolean |
lt(Rational x)
Determine if this rational number is less than the given number. |
boolean |
ltZero()
Determine if this rational number is less than zero. |
Rational |
max(int x,
int y)
Set this rational number to the maximum of the given numbers. |
Rational |
max(int x,
Rational y)
Set this rational number to the maximum of the given numbers. |
Rational |
max(Rational x,
int y)
Set this rational number to the maximum of the given numbers. |
Rational |
max(Rational x,
Rational y)
Set this rational number to the maximum of the given numbers. |
Rational |
min(int x,
int y)
Set this rational number to the minimum of the given numbers. |
Rational |
min(int x,
Rational y)
Set this rational number to the minimum of the given numbers. |
Rational |
min(Rational x,
int y)
Set this rational number to the minimum of the given numbers. |
Rational |
min(Rational x,
Rational y)
Set this rational number to the minimum of the given numbers. |
Rational |
mul(int x,
int y)
Set this rational number to the product of the given numbers. |
Rational |
mul(int x,
Rational y)
Set this rational number to the product of the given numbers. |
Rational |
mul(Rational x,
int y)
Set this rational number to the product of the given numbers. |
Rational |
mul(Rational x,
Rational y)
Set this rational number to the product of the given numbers. |
boolean |
ne(int x)
Determine if this rational number is not equal to the given number. |
boolean |
ne(Rational x)
Determine if this rational number is not equal to the given number. |
Rational |
neg(int x)
Set this rational number to the negative of the given number. |
Rational |
neg(Rational x)
Set this rational number to the negative of the given number. |
boolean |
neZero()
Determine if this rational number is not equal to zero. |
Rational |
sub(int x,
int y)
Set this rational number to the difference of the given numbers. |
Rational |
sub(int x,
Rational y)
Set this rational number to the difference of the given numbers. |
Rational |
sub(Rational x,
int y)
Set this rational number to the difference of the given numbers. |
Rational |
sub(Rational x,
Rational y)
Set this rational number to the difference of the given numbers. |
String |
toString()
Returns a string version of this rational number. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Rational()
public Rational(int value)
value - Value.
public Rational(int numer,
int denom)
numer - Numerator.denom - Denominator.
ArithmeticException - (unchecked exception) Thrown if denom is 0.public Rational(Rational value)
value - Rational number.public Rational(String s)
s - String.
NumberFormatException - (unchecked exception) Thrown if s cannot be parsed into a
rational number.| Method Detail |
|---|
public Rational assign(Rational x)
x - Rational number.
public Rational assign(int x)
x - Integer.
public Rational assign(String s)
s - String.
NumberFormatException - (unchecked exception) Thrown if s cannot be parsed into a
rational number.public Rational neg(Rational x)
x - Rational number.
public Rational neg(int x)
x - Integer.
public Rational abs(Rational x)
x - Rational number.
public Rational abs(int x)
x - Integer.
public Rational intPart(Rational x)
x - Rational number.
public Rational fracPart(Rational x)
x - Rational number.
public Rational add(Rational x,
Rational y)
x - Rational number.y - Rational number.
public Rational add(Rational x,
int y)
x - Rational number.y - Integer.
public Rational add(int x,
Rational y)
x - Integer.y - Rational number.
public Rational add(int x,
int y)
x - Integer.y - Integer.
public Rational sub(Rational x,
Rational y)
x - Rational number.y - Rational number.
public Rational sub(Rational x,
int y)
x - Rational number.y - Integer.
public Rational sub(int x,
Rational y)
x - Integer.y - Rational number.
public Rational sub(int x,
int y)
x - Integer.y - Integer.
public Rational mul(Rational x,
Rational y)
x - Rational number.y - Rational number.
public Rational mul(Rational x,
int y)
x - Rational number.y - Integer.
public Rational mul(int x,
Rational y)
x - Integer.y - Rational number.
public Rational mul(int x,
int y)
x - Integer.y - Integer.
public Rational div(Rational x,
Rational y)
x - Rational number.y - Rational number.
ArithmeticException - (unchecked exception) Thrown if y is 0.
public Rational div(Rational x,
int y)
x - Rational number.y - Integer.
ArithmeticException - (unchecked exception) Thrown if y is 0.
public Rational div(int x,
Rational y)
x - Integer.y - Rational number.
ArithmeticException - (unchecked exception) Thrown if y is 0.
public Rational div(int x,
int y)
x - Integer.y - Integer.
ArithmeticException - (unchecked exception) Thrown if y is 0.
public Rational min(Rational x,
Rational y)
x - Rational number.y - Rational number.
public Rational min(Rational x,
int y)
x - Rational number.y - Integer.
public Rational min(int x,
Rational y)
x - Integer.y - Rational number.
public Rational min(int x,
int y)
x - Integer.y - Integer.
public Rational max(Rational x,
Rational y)
x - Rational number.y - Rational number.
public Rational max(Rational x,
int y)
x - Rational number.y - Integer.
public Rational max(int x,
Rational y)
x - Integer.y - Rational number.
public Rational max(int x,
int y)
x - Integer.y - Integer.
public boolean eqZero()
public boolean neZero()
public boolean ltZero()
public boolean leZero()
public boolean gtZero()
public boolean geZero()
public boolean eq(Rational x)
x - Rational number.
public boolean eq(int x)
x - Integer.
public boolean ne(Rational x)
x - Rational number.
public boolean ne(int x)
x - Integer.
public boolean lt(Rational x)
x - Rational number.
public boolean lt(int x)
x - Integer.
public boolean le(Rational x)
x - Rational number.
public boolean le(int x)
x - Integer.
public boolean gt(Rational x)
x - Rational number.
public boolean gt(int x)
x - Integer.
public boolean ge(Rational x)
x - Rational number.
public boolean ge(int x)
x - Integer.
public int intValue()
public long longValue()
public float floatValue()
public double doubleValue()
public String toString()
toString in class Objectpublic boolean equals(Object obj)
equals in class Objectobj - Object to test.
public int hashCode()
hashCode in class Objectpublic int compareTo(Object obj)
compareTo in interface Comparableobj - Object to compare to.
NullPointerException - (unchecked exception) Thrown if obj is null.
ClassCastException - (unchecked exception) Thrown if obj is not an instance of
class Rational.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||