|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Number
org.rubato.math.arith.Rational
public final class Rational
Rational number arithmetic.
Constructor Summary | |
---|---|
Rational(double d)
Creates a new rational from a double d . |
|
Rational(double d,
int quant)
Creates a new rational from a double d . |
|
Rational(int n)
Creates a new rational number n /1. |
|
Rational(int n,
int d)
Creates a new rational n /d . |
|
Rational(Rational r)
Creates a new rational from r . |
|
Rational(Rational r,
int quant)
Creates a new rational from another rational using given quantization. |
|
Rational(java.lang.String s)
Creates a new rational from its string representation s . |
Method Summary | |
---|---|
Rational |
abs()
Returns the absolute value of this rational. |
void |
add(int n)
Adds the integer n to this number. |
void |
add(Rational r)
Adds r to this number. |
java.lang.Object |
clone()
|
int |
compareTo(Rational r)
|
Rational |
difference(int n)
Returns the difference of this number and the integer n . |
Rational |
difference(Rational r)
Returns the difference of this number and r . |
void |
divide(int x)
Divides this number by the integer n . |
void |
divide(Rational r)
Divides this number by r . |
double |
doubleValue()
Converts this rational to a double. |
boolean |
equals(java.lang.Object object)
|
boolean |
equals(Rational r)
|
float |
floatValue()
Converts this rational to a float. |
static int |
getDefaultQuantization()
Returns the current default quantization; |
int |
getDenominator()
Returns the denominator of this rational. |
int |
getNumerator()
Returns the numerator of this rational. |
static Rational |
getOne()
Returns the rational 1/1. |
static Rational |
getZero()
Returns the rational 0/1. |
int |
hashCode()
Returns the hashcode for this rational. |
int |
intValue()
|
Rational |
inverse()
Returns the inverse of this rational. |
void |
invert()
Inverts this rational. |
boolean |
isIntegral()
|
boolean |
isOne()
Returns true iff this number is 1/1. |
boolean |
isZero()
Returns true iff this number is 0/1. |
long |
longValue()
|
void |
multiply(int n)
Multiplies this number with the integer n . |
void |
multiply(Rational r)
Multiplies this number with r . |
void |
negate()
Negates this rational. |
Rational |
negated()
Returns -this number. |
static Rational |
parseRational(java.lang.String s)
Returns the rational correspoding to its string representation s . |
Rational |
product(int n)
Returns the product of this number and the integer n . |
Rational |
product(Rational r)
Returns the product of this number and r . |
Rational |
quotient(int n)
Returns the quotient of this number and the integer n . |
Rational |
quotient(Rational r)
Returns the quotient of this number and r . |
static void |
resetDefaultQuantization()
Resets the default quantization to the initial value. |
static void |
setDefaultQuantization(int quant)
Sets the default quantization to the given value. |
void |
subtract(int n)
Subtracts the integer n from this number. |
void |
subtract(Rational r)
Subtracts r from this number. |
Rational |
sum(int n)
Returns the sum of this number and the integer n . |
Rational |
sum(Rational r)
Returns the sum of this number and r . |
java.lang.String |
toString()
Returns the string representation of this rational. |
Methods inherited from class java.lang.Number |
---|
byteValue, shortValue |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Rational(int n)
n
/1.
public Rational(int n, int d)
n
/d
.
n
- is the numeratord
- is the denominatorpublic Rational(Rational r)
r
.
Copy constructor.
public Rational(double d, int quant)
d
.
Converts d
with quantization quant
.
public Rational(double d)
d
.
Converts d
with default quantization.
public Rational(Rational r, int quant)
x
/quant
is created
such that x
/quant
<= r
< (x
+1)/quant
.
public Rational(java.lang.String s)
s
.
s
- has the format "n/d" where n and d are integersMethod Detail |
---|
public static Rational getZero()
public static Rational getOne()
public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
public boolean equals(Rational r)
public boolean isZero()
public boolean isOne()
public int compareTo(Rational r)
compareTo
in interface java.lang.Comparable<Rational>
public Rational sum(Rational r)
r
.
public Rational sum(int n)
n
.
public void add(Rational r)
r
to this number.
public void add(int n)
n
to this number.
public Rational difference(Rational r)
r
.
public Rational difference(int n)
n
.
public void subtract(Rational r)
r
from this number.
public void subtract(int n)
n
from this number.
public Rational product(Rational r)
r
.
public Rational product(int n)
n
.
public void multiply(Rational r)
r
.
public void multiply(int n)
n
.
public Rational quotient(Rational r)
r
.
public Rational quotient(int n)
n
.
public void divide(Rational r)
r
.
public void divide(int x)
n
.
public Rational inverse()
public void invert()
public Rational negated()
public void negate()
public int getNumerator()
public int getDenominator()
public Rational abs()
public double doubleValue()
doubleValue
in class java.lang.Number
public float floatValue()
floatValue
in class java.lang.Number
public long longValue()
longValue
in class java.lang.Number
public int intValue()
intValue
in class java.lang.Number
public static Rational parseRational(java.lang.String s)
s
.
public boolean isIntegral()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object clone()
clone
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public static void setDefaultQuantization(int quant)
quant
.
If quant
is 0, the initial default value is
used.
public static void resetDefaultQuantization()
public static int getDefaultQuantization()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |