|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.openmali.number.Rational
public class Rational
Represents a rational number. i.e. an integer over an integer. In order to represent a wide range of values, the data is stored as x + a/b instead of just a/b. So the resultant range of values is slightly wider than the normal integer range. addition, subtraction,multiplication and division are defined.
| Field Summary | |
|---|---|
static int |
APPROXIMATION_THRESHOLD
|
static boolean |
AUTO_SIMPLIFY
should the rational numbers be simplified after every operation? |
static Rational |
ONE
|
static Rational |
ZERO
|
| Constructor Summary | |
|---|---|
Rational()
|
|
Rational(float val)
initializes the rational to an APPROXIMATION of the value of the float parameter, note you should avoid using this method where possible |
|
Rational(int val)
|
|
Rational(int num,
int den)
|
|
Rational(int whole,
int num,
int den)
this = whole + num/den |
|
Rational(Rational val)
|
|
| Method Summary | |
|---|---|
static Rational |
add(Rational a,
Rational b,
Rational passback)
result = a+b this operation can be performed in place i.e. the passback can be the same object as a or b |
Rational |
clone()
|
int |
compareTo(Rational o)
|
static Rational |
div(Rational a,
Rational b,
Rational passback)
result = a/b this operation can be performed in place i.e. the passback can be the same object as a or b |
boolean |
equals(java.lang.Object o)
|
float |
floatValue()
|
static int |
gcd(int a,
int b)
finds the greatest common divisor of two integers |
int |
getDenominator()
|
int |
getNumerator()
|
int |
getWhole()
|
int |
hashCode()
|
static Rational |
mul(Rational a,
Rational b,
Rational passback)
result = a*b this operation can be performed in place i.e. the passback can be the same object as a or b |
void |
negate()
|
static Rational |
parseRational(java.lang.String string)
Reads a single rational number from a string |
void |
set(float value)
initializes the rational to an APPROXIMATION of the value of the float parameter, note you should avoid using this method where possible |
Rational |
set(int whole,
int num,
int den)
|
void |
set(Rational radical)
|
void |
simplify()
attepts to simplify the rational number by dividing by the greatest common devisor, note this is done automatically if AUTO_SIMPLIFY is set to true |
static Rational |
sub(Rational a,
Rational b,
Rational passback)
result = a-b this operation can be performed in place i.e. the passback can be the same object as a or b |
java.lang.String |
toString()
returns a string representation of the number, note: this is compatable with parseRational and the Parser class |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static boolean AUTO_SIMPLIFY
public static int APPROXIMATION_THRESHOLD
public static final Rational ZERO
public static final Rational ONE
| Constructor Detail |
|---|
public Rational(int num,
int den)
public Rational()
public Rational(int whole,
int num,
int den)
public Rational(float val)
val - public Rational(int val)
public Rational(Rational val)
| Method Detail |
|---|
public final Rational set(int whole,
int num,
int den)
public final void set(float value)
public final void set(Rational radical)
public final void negate()
public final float floatValue()
public final int getDenominator()
public final int getWhole()
public final int getNumerator()
public void simplify()
public static Rational add(Rational a,
Rational b,
Rational passback)
public static Rational sub(Rational a,
Rational b,
Rational passback)
public static Rational mul(Rational a,
Rational b,
Rational passback)
public static Rational div(Rational a,
Rational b,
Rational passback)
public static int gcd(int a,
int b)
public Rational clone()
clone in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic int compareTo(Rational o)
compareTo in interface java.lang.Comparable<Rational>public static Rational parseRational(java.lang.String string)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||