|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Number edu.umd.cfar.lamp.viper.geometry.Rational
Represents numbers as a fraction with two BigIntegers. Useful for intersecting polygons and the like.
Constructor Summary | |
Rational()
Constructs a new Rational. |
|
Rational(long numerator)
Constructs a new Rational with the given integer value. |
|
Rational(long numerator,
long denominator)
Constructs a new Rational with the given value. |
|
Rational(Rational old)
Constructs a new Rational with the given value. |
Method Summary | |
Rational |
abs()
Changes this to refer to its abolute value |
byte |
byteValue()
Gets the byte approximation of this rational. |
java.math.BigInteger |
ceiling()
Compute the ceiling as an integer. |
int |
compareTo(java.lang.Object o)
Compares to the other number. |
static void |
divide(Rational numerator,
Rational denominator,
Rational quotient)
Divides two Rationals and stores the result in a third. |
double |
doubleValue()
Gets the double approximation of this rational. |
boolean |
equals(int other)
Tests the equality of this Rational with an int. |
boolean |
equals(java.lang.Object other)
Tests the equality of two Rationals or Numbers. |
float |
floatValue()
Gets the float approximation of this rational. |
java.math.BigInteger |
floor()
Compute the floor as an integer. |
boolean |
greaterThan(int other)
Checks to see if this is greater than an int. |
boolean |
greaterThan(Rational other)
Checks to see if this is greater than another Rational. |
boolean |
greaterThanEqualTo(Rational other)
Checks to see if this is greater than or equal to another Rational. |
int |
hashCode()
Get a hashcode for this number. |
int |
intValue()
Gets the int approximation of this rational. |
boolean |
isNegative()
Tests to see if the number is negative. |
boolean |
isPositive()
Tests to see if the number is positive. |
boolean |
isZero()
Tests to see if the number is zero. |
boolean |
lessThan(int other)
Checks to see if this is less than an int. |
boolean |
lessThan(Rational other)
Checks to see if this is less than another Rational. |
boolean |
lessThanEqualTo(Rational other)
Checks to see if this is less than or equal to another Rational. |
long |
longValue()
Gets the long approximation of this rational. |
static void |
minus(Rational first,
Rational second,
Rational difference)
Subtracts one Rational from another and stores the result into a third. |
static void |
multiply(Rational first,
long second,
Rational result)
Multiplies a Rational with a long and stores the result into another Rational. |
static void |
multiply(Rational first,
Rational second,
Rational result)
Multiplies two Rationals and stores the result into a third. |
Rational |
negate()
Turns negates fraction upside-down, by negating its numerator. |
static Rational |
parseRational(java.lang.String valStr)
|
static void |
plus(Rational first,
Rational second,
Rational result)
Subtracts one Rational from another and stores the result into a third. |
Rational |
reciprocate()
Turns this fraction upside-down, by turning it to its reciprocal. |
Rational |
setTo(long numerator)
Set this to the given value. |
Rational |
setTo(long numerator,
long denominator)
Set this to the given value. |
Rational |
setTo(Rational old)
Set this to the given value. |
short |
shortValue()
Gets the short approximation of this rational. |
Rational |
square()
Square a Rational. |
java.lang.String |
toString()
Gets a string representation. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Rational()
public Rational(long numerator)
numerator
- Integer value to give the Rational.public Rational(long numerator, long denominator)
numerator
- The number on top of the fraction.denominator
- The number on bottom.public Rational(Rational old)
old
- Rational value to give the new one.Method Detail |
public Rational setTo(Rational old)
old
- Rational to set this to.
this
after getting set.public Rational setTo(long numerator)
numerator
- An integer value to set this to.
this
after getting set.public Rational setTo(long numerator, long denominator)
numerator
- The numerator of the fraction.denominator
- The denominator of the fraction.
this
after getting set.public java.lang.String toString()
public int hashCode()
public boolean equals(java.lang.Object other)
other
- The object to compare against this rational number.
true
if they are equal.public boolean equals(int other)
other
- The int to compare against this rational number.
true
if they are equal.public boolean isZero()
true
if the number is zeropublic boolean isNegative()
true
if the number is less than zeropublic boolean isPositive()
true
if the number is greater than zeropublic boolean lessThan(Rational other)
other
- the Rational to test against.
true
iff this is less than the other.public boolean lessThan(int other)
other
- the int to test against.
true
iff this is less than the other.public boolean greaterThan(int other)
other
- the int to test against.
true
iff this is greater than the other.public boolean greaterThan(Rational other)
other
- the number to test against.
true
iff this is greater than the other.public boolean lessThanEqualTo(Rational other)
other
- the number to test against.
true
iff this is less than or equal to the other.public boolean greaterThanEqualTo(Rational other)
other
- the number to test against.
true
iff this is greater than or equal to the other.public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
o
- the number to compare against
public double doubleValue()
double
approximation of this rational.
double
close to the value of this
public float floatValue()
float
approximation of this rational.
float
close to the value of this
public byte byteValue()
byte
approximation of this rational.
byte
closest to the value of this
public short shortValue()
short
approximation of this rational.
short
closest to the value of this
public int intValue()
int
approximation of this rational.
int
closest to the value of this
public java.math.BigInteger floor()
public java.math.BigInteger ceiling()
public long longValue()
long
approximation of this rational.
long
closest to the value of this
public static void plus(Rational first, Rational second, Rational result)
first
- A Rational to add to.second
- A Rational to add.result
- Where to store the result.public static void minus(Rational first, Rational second, Rational difference)
first
- a Rational to subtract something from.second
- a Rational to subtract from the first.difference
- where to store the result.public static void multiply(Rational first, Rational second, Rational result)
first
- A Rational to multiply.second
- Another Rational to multiply.result
- Where to store the result.public static void multiply(Rational first, long second, Rational result)
first
- A Rational to multiply.second
- A long to multiply.result
- Where to store the result.public static void divide(Rational numerator, Rational denominator, Rational quotient)
numerator
- The thing on top, or divisor.denominator
- The thing on the bottom, or dividend.quotient
- Where to store the answer.public Rational negate()
public Rational reciprocate()
public Rational abs()
this
to refer to its abolute value
this
public Rational square()
this
to its square.
this
, now squared.public static Rational parseRational(java.lang.String valStr)
valStr
-
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |