|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.spaceroots.rkcheck.QuadraticSurd
This class implements quadratic irrational numbers (which are also called quadratic surds).
Quadratic irrational numbers are roots of quadratic polynoms with integer coefficients. They can be written:
p1 + p2 sqrt (d)
z = ------------------
q
where p1 and p2 are integers, d is a square free strictly positive
integer and q is a strictly positive integer. This number is a root
of:
2 2 2 2
q X - 2 q p1 X + p1 - d p2 = 0
The set of quadratic irrational numbers associated with a given number d is a field denoted F[sqrt(d)]. This class implements computation within such a field.
| Constructor Summary | |
QuadraticSurd()
Simple constructor. |
|
QuadraticSurd(java.math.BigDecimal r,
java.math.BigDecimal tolerance)
Simple constructor. |
|
QuadraticSurd(java.math.BigInteger l)
Simple constructor. |
|
QuadraticSurd(java.math.BigInteger numerator,
java.math.BigInteger denominator)
Simple constructor. |
|
QuadraticSurd(java.math.BigInteger p1,
java.math.BigInteger p2,
java.math.BigInteger d,
java.math.BigInteger q)
Simple constructor. |
|
QuadraticSurd(long l)
Simple constructor. |
|
QuadraticSurd(long numerator,
long denominator)
Simple constructor. |
|
QuadraticSurd(long p1,
long p2,
long d,
long q)
Simple constructor. |
|
QuadraticSurd(QuadraticSurd qs)
Copy-constructor. |
|
| Method Summary | |
static QuadraticSurd |
add(QuadraticSurd qs1,
QuadraticSurd qs2)
Add two quadratic surds. |
void |
addToSelf(QuadraticSurd qs)
Add a quadratic surd to the instance. |
java.math.BigDecimal |
bigDecimalValue(int scale)
Returns the value of the underlying number as a BigDecimal. |
static QuadraticSurd |
divide(QuadraticSurd qs,
long l)
Divide a quadratic surd by an integer |
static QuadraticSurd |
divide(QuadraticSurd qs1,
QuadraticSurd qs2)
Divide two quadratic surds. |
void |
divideSelf(long l)
Divide the instance by an integer. |
void |
divideSelf(QuadraticSurd qs)
Divide the instance by a quadratic surd. |
double |
doubleValue()
Returns the value of the underlying number as a double. |
boolean |
equals(java.lang.Object o)
Check if the instance is equal to another quadratic surd. |
java.math.BigInteger |
getDenominator()
Get the denominator. |
java.math.BigInteger |
getRationalNumerator()
Get the numerator of the rational part. |
java.math.BigInteger |
getRootCoefficient()
Get the coefficient of the irrational part. |
java.math.BigInteger |
getRootElement()
Get the root element of the irrational part. |
int |
hashCode()
Returns a hash code value for the object. |
static QuadraticSurd |
invert(QuadraticSurd qs)
Invert a quadratic surd. |
void |
invertSelf()
Invert the instance. |
boolean |
isInteger()
Check if the number is integer. |
boolean |
isOne()
Check if the instance is equal to 1. |
boolean |
isRational()
Check if the instance holds a rational number. |
boolean |
isZero()
Check if the instance is equal to 0. |
static QuadraticSurd |
multiply(QuadraticSurd qs,
long l)
Multiply a quadratic surd by an integer. |
static QuadraticSurd |
multiply(QuadraticSurd qs1,
QuadraticSurd qs2)
Multiply two quadratic surds. |
void |
multiplySelf(long l)
Multiply the instance by an integer. |
void |
multiplySelf(QuadraticSurd qs)
Multiply the instance by a quadratic surd. |
static QuadraticSurd |
negate(QuadraticSurd qs)
Negate a quadratic surd. |
void |
negateSelf()
Negate the instance |
boolean |
sameField(QuadraticSurd qs)
Check if a quadratic surd belong to the same field as the instance. |
static QuadraticSurd |
subtract(QuadraticSurd qs1,
QuadraticSurd qs2)
Subtract two quadratic surds. |
void |
subtractFromSelf(QuadraticSurd qs)
Subtract a quadratic surd to the instance. |
java.lang.String |
toString()
Returns a string representation of the underlying number. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public QuadraticSurd()
public QuadraticSurd(long l)
l - value of the quadratic surdpublic QuadraticSurd(java.math.BigInteger l)
l - value of the quadratic surd
public QuadraticSurd(long numerator,
long denominator)
numerator - numerator of the quadratic surddenominator - denominator of the quadratic surd
java.lang.ArithmeticException - if the denominator is zero
public QuadraticSurd(java.math.BigInteger numerator,
java.math.BigInteger denominator)
numerator - numerator of the quadratic surddenominator - denominator of the quadratic surd
java.lang.ArithmeticException - if the denominator is zero
public QuadraticSurd(long p1,
long p2,
long d,
long q)
p1 - integer part of the numeratorp2 - coefficient of the root part of the numeratord - rootq - denominator
java.lang.ArithmeticException - if the root is negative
java.lang.ArithmeticException - if the denominator is zero
public QuadraticSurd(java.math.BigInteger p1,
java.math.BigInteger p2,
java.math.BigInteger d,
java.math.BigInteger q)
p1 - integer part of the numeratorp2 - coefficient of the root part of the numeratord - rootq - denominator
java.lang.ArithmeticException - if the root is negative
java.lang.ArithmeticException - if the denominator is zero
public QuadraticSurd(java.math.BigDecimal r,
java.math.BigDecimal tolerance)
r - real number to approximatetolerance - tolerance allowed for the approximationpublic QuadraticSurd(QuadraticSurd qs)
qs - quadratic surd to copy| Method Detail |
public boolean sameField(QuadraticSurd qs)
qs - quadratic surd to check against the instance
public void negateSelf()
public static QuadraticSurd negate(QuadraticSurd qs)
qs - quadratic surd to negate
public void addToSelf(QuadraticSurd qs)
throws java.lang.ArithmeticException
qs - quadratic surd to add.
java.lang.ArithmeticException - if the two quadratic surds do not
belong to the same field (i.e. if they do not share the same
root)
public static QuadraticSurd add(QuadraticSurd qs1,
QuadraticSurd qs2)
throws java.lang.ArithmeticException
qs1 - first quadratic surdqs2 - second quadratic surd
java.lang.ArithmeticException - if the two quadratic surds do not
belong to the same field (i.e. if they do not share the same
root)
public void subtractFromSelf(QuadraticSurd qs)
throws java.lang.ArithmeticException
qs - quadratic surd to subtract.
java.lang.ArithmeticException - if the two quadratic surds do not
belong to the same field (i.e. if they do not share the same
root)
public static QuadraticSurd subtract(QuadraticSurd qs1,
QuadraticSurd qs2)
throws java.lang.ArithmeticException
qs1 - first quadratic surdqs2 - second quadratic surd
java.lang.ArithmeticException - if the two quadratic surds do not
belong to the same field (i.e. if they do not share the same
root)public void multiplySelf(long l)
l - integer to multiply by
public static QuadraticSurd multiply(QuadraticSurd qs,
long l)
qs - quadratic surdl - integer to multiply by
public void multiplySelf(QuadraticSurd qs)
throws java.lang.ArithmeticException
qs - quadratic surd to multiply by
java.lang.ArithmeticException - if the two quadratic surds do not
belong to the same field (i.e. if they do not share the same
root)
public static QuadraticSurd multiply(QuadraticSurd qs1,
QuadraticSurd qs2)
throws java.lang.ArithmeticException
qs1 - first quadratic surdqs2 - second quadratic surd
java.lang.ArithmeticException - if the two quadratic surds do not
belong to the same field (i.e. if they do not share the same
root)
public void divideSelf(long l)
throws java.lang.ArithmeticException
l - integer to divide by
java.lang.ArithmeticException - if l is zero
public static QuadraticSurd divide(QuadraticSurd qs,
long l)
throws java.lang.ArithmeticException
qs - quadratic surdl - integer
java.lang.ArithmeticException - if l is zero
public void divideSelf(QuadraticSurd qs)
throws java.lang.ArithmeticException
qs - quadratic surd to divide by
java.lang.ArithmeticException - if qs is zero
java.lang.ArithmeticException - if the two quadratic surds do not
belong to the same field (i.e. if they do not share the same
root)
public static QuadraticSurd divide(QuadraticSurd qs1,
QuadraticSurd qs2)
qs1 - first quadratic surdqs2 - second quadratic surd
java.lang.ArithmeticException - if qs2 is zero
java.lang.ArithmeticException - if the two quadratic surds do not
belong to the same field (i.e. if they do not share the same
root)
public void invertSelf()
throws java.lang.ArithmeticException
java.lang.ArithmeticException - if the instance is zero
public static QuadraticSurd invert(QuadraticSurd qs)
throws java.lang.ArithmeticException
qs - quadratic surd to invert
java.lang.ArithmeticException - if qs is zeropublic boolean isZero()
public boolean isOne()
public boolean isInteger()
public boolean isRational()
public boolean equals(java.lang.Object o)
public int hashCode()
public java.math.BigInteger getRationalNumerator()
If the instance is a number of the form:
p1 + p2 sqrt (d)
z = ------------------
q
then this method returns p1
public java.math.BigInteger getRootCoefficient()
If the instance is a number of the form:
p1 + p2 sqrt (d)
z = ------------------
q
then this method returns p2
public java.math.BigInteger getRootElement()
If the instance is a number of the form:
p1 + p2 sqrt (d)
z = ------------------
q
then this method returns d
public java.math.BigInteger getDenominator()
If the instance is a number of the form:
p1 + p2 sqrt (d)
z = ------------------
q
then this method returns q
public double doubleValue()
public java.math.BigDecimal bigDecimalValue(int scale)
scale - scale of the BigDecimal to return
public java.lang.String toString()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||