public class Mpq extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<Mpq>, java.lang.Cloneable
This class wraps mpq_t
GMP objects.
Constructor and Description |
---|
Mpq()
Constructs a rational initialized to 0/1.
|
Mpq(java.math.BigInteger op)
Constructs a rational equal to the integer op.
|
Mpq(java.math.BigInteger num,
java.math.BigInteger den)
Constructs a rational equal to num/den.
|
Mpq(double d)
Constructs a rational equal to the double d.
|
Mpq(int op)
Constructs a rational equal to the integer op.
|
Mpq(int num,
int den)
Constructs a rational equal to num/den.
|
Mpq(Mpq op)
Constructs a copy of op.
|
Mpq(Mpz op)
Constructs a rational equal to the integer op.
|
Mpq(Mpz num,
Mpz den)
Constructs a rational equal to num/den.
|
Mpq(java.lang.String s)
Constructs a rational from the String s.
|
Mpq(java.lang.String s,
int b)
Constructs a rational from the String s expressed in base b.
|
Modifier and Type | Method and Description |
---|---|
void |
abs()
Replaces this with |this|.
|
void |
abs(Mpq arg)
Stores |arg| into this.
|
void |
add(Mpq arg)
Adds arg to this.
|
void |
add(Mpq arg1,
Mpq arg2)
Stores arg1+arg2 into this.
|
void |
canonicalize()
Puts the fraction into normal form.
|
Mpq |
clone()
Creates a new Mpq initialized with the value of this.
|
int |
cmp(int num,
int den)
Returns a positive, null, or negative number when this is respectively
strictly greater, equal, or strictly smaller than num/den.
|
int |
cmp(Mpq op)
Returns a positive, null, or negative number when this is respectively
strictly greater, equal, or strictly smaller than op.
|
int |
compareTo(Mpq x)
Compare the value of this and x.
|
MpzRef |
denRef()
Returns a reference to the denominator of this.
|
void |
div(Mpq arg)
Divides this by arg.
|
void |
div(Mpq arg1,
Mpq arg2)
Stores arg1/arg2 into this.
|
void |
div2exp(int arg)
Divides this by (2^arg).
|
void |
div2exp(Mpq arg1,
int arg2)
Stores arg1/(2^arg2) into this.
|
void |
divRev(Mpq arg)
Stores arg/this into this.
|
double |
doubleValue()
Returns this as a double.
|
boolean |
equals(java.lang.Object x)
Whether x is a Mpq and has the same value as this.
|
protected void |
finalize()
Deallocates the underlying mpq_t GMP object.
|
Mpz |
getDen()
Returns a copy of the denominator of this.
|
Mpz |
getNum()
Returns a copy of the numerator of this.
|
int |
hashCode()
Returns a hash of the value of this.
|
void |
inv()
Replaces this with 1/this.
|
void |
inv(Mpq arg)
Stores 1/arg into this.
|
boolean |
isEqual(Mpq op)
Whether this equals op.
|
boolean |
isPhysicalEqual(Mpq x)
Whether this and x have the same address in memory.
|
void |
mul(Mpq arg)
Multiply this by arg.
|
void |
mul(Mpq arg1,
Mpq arg2)
Stores arg1*arg2 into this.
|
void |
mul2exp(int arg)
Multiply this by 2^arg.
|
void |
mul2exp(Mpq arg1,
int arg2)
Stores arg1*(2^arg2) into this.
|
void |
neg()
Replaces this with -this.
|
void |
neg(Mpq arg)
Stores -arg into this.
|
MpzRef |
numRef()
Returns a reference to the numerator of this.
|
void |
set(java.math.BigInteger op)
Sets this to the integer op.
|
void |
set(java.math.BigInteger num,
java.math.BigInteger den)
Sets this to num/den.
|
void |
set(double d)
Sets this to the double number.
|
void |
set(int op)
Sets this to the integer op.
|
void |
set(int num,
int den)
Sets this to num/den.
|
void |
set(Mpq op)
Copies the argument into this.
|
void |
set(Mpz op)
Sets this to the integer op.
|
void |
set(Mpz num,
Mpz den)
Sets this to num/den.
|
void |
set(java.lang.String s)
Sets this to the String s.
|
void |
set(java.lang.String s,
int b)
Sets this to the String s expressed in base b.
|
void |
setDen(java.math.BigInteger op)
Changes the denominator of this.
|
void |
setDen(int op)
Changes the denominator of this.
|
void |
setDen(Mpz op)
Changes the denominator of this.
|
void |
setNum(java.math.BigInteger op)
Changes the numerator of this.
|
void |
setNum(int op)
Changes the numerator of this.
|
void |
setNum(Mpz op)
Changes the numerator of this.
|
int |
sgn()
Returns +1, 0, or -1 when this is respectively strictly positive, null,
or strictly negative.
|
int |
size()
Returns the size (in GMP limbs) of the internal representation of
this.
|
void |
sub(Mpq arg)
Subtracts arg from this.
|
void |
sub(Mpq arg1,
Mpq arg2)
Stores arg1-arg2 into this.
|
void |
subRev(Mpq arg)
Replaces this with arg-this.
|
java.lang.String |
toString()
Returns a String representation of this in base 10.
|
java.lang.String |
toString(int b)
Returns a String representation of this in base b.
|
public Mpq()
public Mpq(Mpq op)
public Mpq(Mpz op)
public Mpq(java.math.BigInteger op)
public Mpq(int op)
public Mpq(double d)
There is no rounding, the conversion is exact.
public Mpq(java.lang.String s, int b)
The String can have a fraction / symbol.
The result is canonicalized.
Mpz.Mpz(String,int)
public Mpq(java.lang.String s)
The String can have a fraction / symbol.
The result is canonicalized.
Mpz.Mpz(String)
public Mpq(Mpz num, Mpz den)
The result is canonicalized.
public Mpq(java.math.BigInteger num, java.math.BigInteger den)
The result is canonicalized.
public Mpq(int num, int den)
The result is canonicalized.
protected void finalize()
finalize
in class java.lang.Object
public void canonicalize()
Removes common factors in the numerator and denominator, and makes the denominator positive.
All arithmetic functions assume and return canonical fractions.
However, pure assignment functions (including separate assignments
of denominators and numerators, directly or through a
MpzRef
reference) do not canonicalize the assigned
object, and so, the function must be called by the user before
arithmetic operations can be performed.
public Mpq clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public void set(Mpq op)
public void set(Mpz op)
public void set(java.math.BigInteger op)
public void set(int op)
public void set(Mpz num, Mpz den)
canonicalize()
must be called manually if the fraction
is not canonical.
public void set(java.math.BigInteger num, java.math.BigInteger den)
canonicalize()
must be called manually if the fraction
is not canonical.
public void set(int num, int den)
canonicalize()
must be called manually if the fraction
is not canonical.
public void set(double d)
There is no rounding: the conversion is exact.
public void set(java.lang.String s, int b)
The String can have a fraction / symbol.
canonicalize()
must be called manually if the fraction
is not canonical.
Mpz.Mpz(String,int)
public void set(java.lang.String s)
The String can have a fraction / symbol.
canonicalize()
must be called manually if the fraction
is not canonical.
Mpz.Mpz(String)
public void setNum(Mpz op)
canonicalize()
must be called manually if the fraction
is not canonical.
public void setNum(int op)
canonicalize()
must be called manually if the fraction
is not canonical.
public void setNum(java.math.BigInteger op)
canonicalize()
must be called manually if the fraction
is not canonical.
public void setDen(Mpz op)
canonicalize()
must be called manually if the fraction
is not canonical.
public void setDen(int op)
canonicalize()
must be called manually if the fraction
is not canonical.
public void setDen(java.math.BigInteger op)
canonicalize()
must be called manually if the fraction
is not canonical.
public double doubleValue()
If this cannot be represented as a double, the result is truncated.
Overflows cause infinities to be returned.
public java.lang.String toString(int b)
b
- must be between 2 and 62.public java.lang.String toString()
toString
in class java.lang.Object
public Mpz getNum()
public Mpz getDen()
public MpzRef numRef()
public MpzRef denRef()
public void add(Mpq arg)
public void sub(Mpq arg)
public void subRev(Mpq arg)
public void mul(Mpq arg)
public void mul2exp(Mpq arg1, int arg2)
public void mul2exp(int arg)
public void div(Mpq arg)
public void divRev(Mpq arg)
public void div2exp(Mpq arg1, int arg2)
public void div2exp(int arg)
public void neg(Mpq arg)
public void neg()
public void abs(Mpq arg)
public void abs()
public void inv(Mpq arg)
public void inv()
public int size()
public int cmp(Mpq op)
public int cmp(int num, int den)
den must be positive.
public int sgn()
public boolean isEqual(Mpq op)
This method is faster than calling cmp, as fractions are assumed to be canonical.
public boolean equals(java.lang.Object x)
equals
in class java.lang.Object
public int compareTo(Mpq x)
compareTo
in interface java.lang.Comparable<Mpq>
public int hashCode()
hashCode
in class java.lang.Object
public boolean isPhysicalEqual(Mpq x)