Class Mpz
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<Mpz>
- Direct Known Subclasses:
MpzRef
This class wraps mpz_t
GMP objects.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
This value can be returned by bit-searching or bit-counting operations. -
Constructor Summary
ConstructorsConstructorDescriptionMpz()
Constructs an uninitialized number.Mpz
(double d) Constructs a number initialized with a double.Mpz
(int i) Constructs a number initialized with an integer.Mpz
(int sign, byte[] mag) Constructs a number from a unsigned stored in a big-endian byte array and a sign.Constructs a copy of its argument.Constructs a number initialized from a string representation.Constructs a number initialized from a string representation in base b.Mpz
(BigInteger b) Constructs a number initialized from a Java big integer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
abs()
Replaces this with |this|.void
Stores |arg| into this.void
add
(int arg) Adds arg to this.void
Adds arg to this.void
Stores arg1+arg2 into this.void
Stores arg1+arg2 into this.void
Stores this+arg1*arg2 into this.void
Stores this+arg1*arg2 into this.void
Stores the bitwise and of this and op into this.void
Stores the bitwise and of op1 and op2 into this.Returns this as a Java big integer.void
bin
(int n, int k) Stores into this the binomial coefficient (n k).void
Stores into this the binomial coefficient (n k).byte[]
Returns the magnitude of this.int
cdivQ
(int d) Divides this by d, rounds towards +oo, and returns the remainder.void
Divides this by d and rounds towards +oo.int
Stores the quotient of n/d rounded towards +oo into this, and returns the remainder.void
Stores the quotient of n/d rounded towards +oo into this.void
Stores the quotient of n/(2^d) rounded towards +oo into this.int
Stores the quotient of n/d rounded towards +oo into this, the remainder into r, and returns the remainder.void
Stores the quotient of n/d rounded towards +oo into this and the remainder into r.int
cdivR
(int d) Returns the remainder of of this/d rounded towards +oo.int
Stores the remainder of n/d rounded towards +oo into this, and returns the remainder.void
Stores the remainder of n/d rounded towards +oo into this.void
Stores the remainder of n/(2^d) rounded towards +oo into this.clone()
Creates a new Mpz initialized with the value of this.void
clrBit
(int pos) Sets the pos-th bit to 0 in this.int
cmp
(double op) Returns a positive, null, or negative number when this is respectively strictly greater, equal, or strictly smaller than op.int
cmp
(int op) Returns a positive, null, or negative number when this is respectively strictly greater, equal, or strictly smaller than op.int
Returns a positive, null, or negative number when this is respectively strictly greater, equal, or strictly smaller than op.int
cmpAbs
(double op) Returns a positive, null, or negative number when |this| is respectively strictly greater, equal, or strictly smaller than |op|.int
cmpAbs
(int op) Returns a positive, null, or negative number when |this| is respectively strictly greater, equal, or strictly smaller than |op|.int
Returns a positive, null, or negative number when |this| is respectively strictly greater, equal, or strictly smaller than |op|.int
Compare the value of this and x.void
divExact
(int d) Divides this by d, assuming that d divides this. d must be positive.void
Divides this by d, assuming that d divides this.void
Stores n/d into this, assuming that d divides n. d must be positive.void
Stores n/d into this, assuming that d divides n.double
doubleExponentValue
(int[] r) Converts the integer to a mantissa and exponent.double
Returns this as a double.boolean
Whether x is a Mpz and has the same value as this.void
fac
(int op) Stores op!int
fdivQ
(int d) Divides this by d, rounds towards -oo, and returns the remainder.void
Divides this by d and rounds towards -oo.int
Stores the quotient of n/d rounded towards -oo into this, and returns the remainder.void
Stores the quotient of n/d rounded towards -oo into this.void
Stores the quotient of n/(2^d) rounded towards -oo into this.int
Stores the quotient of n/d rounded towards -oo into this, the remainder into r, and returns the remainder.void
Stores the quotient of n/d rounded towards -oo into this and the remainder into r.int
fdivR
(int d) Returns the remainder of of this/d rounded towards -oo.int
Stores the remainder of n/d rounded towards -oo into this, and returns the remainder.void
Stores the remainder of n/d rounded towards -oo into this.void
Stores the remainder of n/(2^d) rounded towards -oo into this.void
fib
(int n) Stores into this the n-th Fibonacci number.void
Stores into this the n-th Fibonacci number, and into r the n-1-th Fibonacci number.boolean
fitsInt()
Whether this can fit in an int.int
Returns the greatest common divisor of op1 and op2.void
Stores into this the greatest common divisor of op1 and op2.void
Stores the greatest common divisor of op1 and op2 into this.int
Returns the Hamming distance between this and op.int
hashCode()
Returns a hash of the value of this.int
intValue()
Returns this as an integer.boolean
Stores the inverse of op1 modulo op2 into this.boolean
isCongruent
(int c, int d) Returns true if this equals c modulo d.boolean
isCongruent
(Mpz c, Mpz d) Returns true if this equals c modulo d.boolean
isCongruent2exp
(Mpz c, int d) Returns true if this equals c modulo 2^d.boolean
isDivisible
(int d) Returns true if d divides this.boolean
isDivisible
(Mpz d) Returns true if d divides this.boolean
isDivisible2exp
(int d) Returns true if 2^d divides this.boolean
Whether this and x have the same value.boolean
isEven()
Whether this is even.boolean
isOdd()
Whether this is odd.boolean
Returns true if this has the form a^b for some a and b > 1.boolean
Returns true if this has the form a^2 for some a.boolean
Whether this and x have the same address in memory.int
isProbabPrime
(int r) Returns 2 if this is definitely prime, 1 if it is probably prime, and 0 if it is definitely composite.static int
Returns the Jacobi symbol of a and b.static int
Returns the Jacobi symbol with the Kronecker extension.static int
Returns the Jacobi symbol with the Kronecker extension.static int
Returns the Jacobi symbol with the Kronecker extension.void
Stores into this the least common multiple of op1 and op2.void
Stores into this the least common multiple of op1 and op2.static int
Returns the Legendre symbol.void
lucnum
(int n) Stores into this the n-th Lucas number.void
Stores into this the n-th Lucas number, and into r the n-1-th Lucas number.int
mod
(int d) Replaces this with this mod |d|.void
Replaces this with this mod |d|.int
Stores n mod |d| into this and returns it.void
Stores n mod |d| into this.void
mul
(int arg) Multiplies this by arg.void
Multiplies this by arg.void
Stores arg1*arg2 into this.void
Stores arg1*arg2 into this.void
mul2exp
(int arg) Multiplies this by 2^arg.void
Stores arg1*2^arg2 into this.void
neg()
Replaces this with -this.void
Stores -arg into this.void
Stores into this the next prime greater than op.void
not()
Stores the bitwise complement of this into this.void
Stores the bitwise complement of op into this.void
notBit
(int pos) Inverts the pos-th bit in this.void
Stores the bitwise or of this and op into this.void
Stores the bitwise or of op1 and op2 into this.int
popCount()
Returns the number of bits set to 1 in this.void
pow
(int e) Takes the e-th power of this.void
pow
(int b, int e) Stores b^e into this.void
Stores b^e into this.void
Stores b^e mod m into this.void
Stores b^e mod m into this.void
Stores into this a uniformly distributed random number in 0..n-1.void
randomBits
(RandState r, int n) Stores into this a uniformly distributed random number with n bits (i.e., in 0..2^n-1).int
Removes from this all occurrences of factor f.int
Stores into this op with all occurrences of factor f removed.boolean
root
(int n) Takes the n-th root of this, truncated.boolean
Stores the n-th root of op into this, truncated.void
Stores the n-th root of op into this, truncated, and the remainder op-this^n into r.void
rRandomBits
(RandState r, int n) Stores into this a random number with n bits, and long strings of zeros and ones in its binary representation.int
scan0
(int pos) Returns the position of the first bit set to 0 at or after position pos.int
scan1
(int pos) Returns the position of the first bit set to 1 at or after position pos.void
set
(double d) Sets this to a double.void
set
(int i) Sets this to an integer.void
set
(int sign, byte[] mag) Sets the value of this given a magnitude and a sign.void
Copies the argument into this.void
Sets this to the String s.void
Sets this to the String s expressed in base b.void
set
(BigInteger b) Sets this to a Java big integer.void
setBit
(int pos) Sets the pos-th bit to 1 in 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.int
sizeInBase
(int b) Returns the number of digits necessary to represent |this| in base b.void
sqrt()
Takes the truncated square root of this.void
Stores the truncated square root of op into this.void
Stores the square root of op into this, truncated, and the remainder op-this^2 into r.void
sub
(int arg) Subtracts arg from this.void
Stores arg1-arg2 into this.void
Subtracts arg from this.void
Stores arg1-arg2 into this.void
Stores arg1-arg2 into this.void
Stores this-arg1*arg2 into this.void
Stores this-arg1*arg2 into this.void
subRev
(int arg) Replaces this with arg-this.int
tdivQ
(int d) Divides this by d, rounds towards 0, and returns the remainder.void
Divides this by d and rounds towards 0.int
Stores the quotient of n/d rounded towards 0 into this, and returns the remainder.void
Stores the quotient of n/d rounded towards 0 into this.void
Stores the quotient of n/(2^d) rounded towards 0 into this.int
Stores the quotient of n/d rounded towards 0 into this, the remainder into r, and returns the remainder.void
Stores the quotient of n/d rounded towards 0 into this and the remainder into r.int
tdivR
(int d) Returns the remainder of of this/d rounded towards 0.int
Stores the remainder of n/d rounded towards 0 into this, and returns the remainder.void
Stores the remainder of n/d rounded towards 0 into this.void
Stores the remainder of n/(2^d) rounded towards 0 into this.toString()
Returns a String representation this in base 10.toString
(int b) Returns a String representation of this in base b.boolean
tstBit
(int pos) Returns true if the pos-th bit in this is 1.void
Stores the bitwise xor of this and op into this.void
Stores the bitwise xor of op1 and op2 into this.
-
Field Details
-
infinite
public static final int infiniteThis value can be returned by bit-searching or bit-counting operations.- See Also:
-
-
Constructor Details
-
Mpz
public Mpz()Constructs an uninitialized number. -
Mpz
Constructs a copy of its argument. -
Mpz
public Mpz(int i) Constructs a number initialized with an integer. -
Mpz
public Mpz(double d) Constructs a number initialized with a double.The value is truncated to an integer.
-
Mpz
Constructs a number initialized from a Java big integer. -
Mpz
Constructs a number initialized from a string representation in base b.- Parameters:
b
- must be either 0, or between 2 and 62. When b is 0, the leading characters are used to determine the base (0x and 0X for hexadecimal, 0b and 0B for binary, 0 for octal, decimal otherwise).
-
Mpz
Constructs a number initialized from a string representation.The leading characters are used to determine whether base: 0x and 0X for hexadecimal, 0b and 0B for binary, 0 for octal, and decimal otherwise.
-
Mpz
public Mpz(int sign, byte[] mag) Constructs a number from a unsigned stored in a big-endian byte array and a sign.
-
-
Method Details
-
set
public void set(int sign, byte[] mag) Sets the value of this given a magnitude and a sign.Used during deserialization.
mag is the absolute value encoded in a byte array in big endian order.
-
byteArrayValue
public byte[] byteArrayValue()Returns the magnitude of this.User during serialization.
The magnitude is the absolute value, and it is returned as a byte array stored in big-endian order.
-
clone
Creates a new Mpz initialized with the value of this.- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
set
Copies the argument into this. -
set
public void set(int i) Sets this to an integer. -
set
public void set(double d) Sets this to a double.The value is truncated.
-
set
Sets this to a Java big integer. -
set
Sets this to the String s expressed in base b.- See Also:
-
set
Sets this to the String s.- See Also:
-
intValue
public int intValue()Returns this as an integer.The result is truncated if it does not fit in an integer.
- See Also:
-
doubleValue
public double doubleValue()Returns this as a double.If this cannot be represented as a double, the result is truncated.
Overflows cause infinities to be returned.
-
doubleExponentValue
public double doubleExponentValue(int[] r) Converts the integer to a mantissa and exponent.The mantissa m returned is such that 0.5 <= |m| < 1, truncated to fit double.
The exponent is stored into r[0].
-
bigIntegerValue
Returns this as a Java big integer. -
toString
Returns a String representation of this in base b.- Parameters:
b
- must be between 2 and 62.
-
toString
Returns a String representation this in base 10. -
add
Stores arg1+arg2 into this. -
add
Stores arg1+arg2 into this. -
add
Adds arg to this. -
add
public void add(int arg) Adds arg to this. -
sub
Stores arg1-arg2 into this. -
sub
Stores arg1-arg2 into this. -
sub
Stores arg1-arg2 into this. -
sub
Subtracts arg from this. -
sub
public void sub(int arg) Subtracts arg from this. -
subRev
public void subRev(int arg) Replaces this with arg-this. -
mul
Stores arg1*arg2 into this. -
mul
Stores arg1*arg2 into this. -
mul
Multiplies this by arg. -
mul
public void mul(int arg) Multiplies this by arg. -
addMul
Stores this+arg1*arg2 into this. -
addMul
Stores this+arg1*arg2 into this. -
subMul
Stores this-arg1*arg2 into this. -
subMul
Stores this-arg1*arg2 into this. -
mul2exp
Stores arg1*2^arg2 into this.arg2 must be positive.
-
mul2exp
public void mul2exp(int arg) Multiplies this by 2^arg.arg must be positive.
-
neg
Stores -arg into this. -
neg
public void neg()Replaces this with -this. -
abs
Stores |arg| into this. -
abs
public void abs()Replaces this with |this|. -
cdivQ
Stores the quotient of n/d rounded towards +oo into this.- Throws:
ArithmeticException
-
cdivQ
Divides this by d and rounds towards +oo.- Throws:
ArithmeticException
-
cdivR
Stores the remainder of n/d rounded towards +oo into this.- Throws:
ArithmeticException
-
cdivQR
Stores the quotient of n/d rounded towards +oo into this and the remainder into r.- Throws:
ArithmeticException
-
cdivQ
Stores the quotient of n/d rounded towards +oo into this, and returns the remainder.d must be positive.
- Throws:
ArithmeticException
-
cdivQ
Divides this by d, rounds towards +oo, and returns the remainder.d must be positive.
- Throws:
ArithmeticException
-
cdivR
Stores the remainder of n/d rounded towards +oo into this, and returns the remainder.d must be positive.
- Throws:
ArithmeticException
-
cdivQR
Stores the quotient of n/d rounded towards +oo into this, the remainder into r, and returns the remainder.d must be positive.
- Throws:
ArithmeticException
-
cdivR
Returns the remainder of of this/d rounded towards +oo.this is unchanged.
d must be positive.
- Throws:
ArithmeticException
-
cdivQ2exp
Stores the quotient of n/(2^d) rounded towards +oo into this.d must be positive.
- Throws:
ArithmeticException
-
cdivR2exp
Stores the remainder of n/(2^d) rounded towards +oo into this.d must be positive.
- Throws:
ArithmeticException
-
fdivQ
Stores the quotient of n/d rounded towards -oo into this.- Throws:
ArithmeticException
-
fdivQ
Divides this by d and rounds towards -oo.- Throws:
ArithmeticException
-
fdivR
Stores the remainder of n/d rounded towards -oo into this.- Throws:
ArithmeticException
-
fdivQR
Stores the quotient of n/d rounded towards -oo into this and the remainder into r.- Throws:
ArithmeticException
-
fdivQ
Stores the quotient of n/d rounded towards -oo into this, and returns the remainder.d must be positive.
- Throws:
ArithmeticException
-
fdivQ
Divides this by d, rounds towards -oo, and returns the remainder.d must be positive.
- Throws:
ArithmeticException
-
fdivR
Stores the remainder of n/d rounded towards -oo into this, and returns the remainder.d must be positive.
- Throws:
ArithmeticException
-
fdivQR
Stores the quotient of n/d rounded towards -oo into this, the remainder into r, and returns the remainder.d must be positive.
- Throws:
ArithmeticException
-
fdivR
Returns the remainder of of this/d rounded towards -oo.this is unchanged.
d must be positive.
- Throws:
ArithmeticException
-
fdivQ2exp
Stores the quotient of n/(2^d) rounded towards -oo into this.- Throws:
ArithmeticException
-
fdivR2exp
Stores the remainder of n/(2^d) rounded towards -oo into this.d must be positive.
- Throws:
ArithmeticException
-
tdivQ
Stores the quotient of n/d rounded towards 0 into this.- Throws:
ArithmeticException
-
tdivQ
Divides this by d and rounds towards 0.- Throws:
ArithmeticException
-
tdivR
Stores the remainder of n/d rounded towards 0 into this.- Throws:
ArithmeticException
-
tdivQR
Stores the quotient of n/d rounded towards 0 into this and the remainder into r.- Throws:
ArithmeticException
-
tdivQ
Stores the quotient of n/d rounded towards 0 into this, and returns the remainder.d must be positive.
- Throws:
ArithmeticException
-
tdivQ
Divides this by d, rounds towards 0, and returns the remainder.d must be positive.
- Throws:
ArithmeticException
-
tdivR
Stores the remainder of n/d rounded towards 0 into this, and returns the remainder.d must be positive.
- Throws:
ArithmeticException
-
tdivQR
Stores the quotient of n/d rounded towards 0 into this, the remainder into r, and returns the remainder.d must be positive.
- Throws:
ArithmeticException
-
tdivR
Returns the remainder of of this/d rounded towards 0.this is unchanged.
d must be positive.
- Throws:
ArithmeticException
-
tdivQ2exp
Stores the quotient of n/(2^d) rounded towards 0 into this.d must be positive.
- Throws:
ArithmeticException
-
tdivR2exp
Stores the remainder of n/(2^d) rounded towards 0 into this.d must be positive.
- Throws:
ArithmeticException
-
mod
Stores n mod |d| into this.- Throws:
ArithmeticException
-
mod
Replaces this with this mod |d|.- Throws:
ArithmeticException
-
mod
Stores n mod |d| into this and returns it.- Throws:
ArithmeticException
-
mod
Replaces this with this mod |d|.- Throws:
ArithmeticException
-
divExact
Stores n/d into this, assuming that d divides n.- Throws:
ArithmeticException
-
divExact
Divides this by d, assuming that d divides this.- Throws:
ArithmeticException
-
divExact
Stores n/d into this, assuming that d divides n. d must be positive.- Throws:
ArithmeticException
-
divExact
Divides this by d, assuming that d divides this. d must be positive.- Throws:
ArithmeticException
-
isDivisible
Returns true if d divides this.Only 0 is divisible by 0.
-
isDivisible
public boolean isDivisible(int d) Returns true if d divides this.d must be positive.
Only 0 is divisible by 0.
-
isDivisible2exp
public boolean isDivisible2exp(int d) Returns true if 2^d divides this.d must be positive.
-
isCongruent
Returns true if this equals c modulo d.When d=0, returns true if this equals c.
-
isCongruent
public boolean isCongruent(int c, int d) Returns true if this equals c modulo d.d must be positive.
When d=0, returns true if this equals c.
-
isCongruent2exp
Returns true if this equals c modulo 2^d.d must be positive.
-
pow
Stores b^e mod m into this.Throws an ArithmeticException if e < 0 and b has no inverse modulo m.
- Throws:
ArithmeticException
-
pow
Stores b^e mod m into this.e must be positive.
- Throws:
ArithmeticException
-
pow
Stores b^e into this.e must be positive.
0^0 is 1.
-
pow
public void pow(int e) Takes the e-th power of this.e must be positive.
0^0 is 1.
-
pow
public void pow(int b, int e) Stores b^e into this.b and e must be positive.
0^0 is 1.
-
root
Stores the n-th root of op into this, truncated.Returns true if the computation was exact.
n must be positive.
-
root
public boolean root(int n) Takes the n-th root of this, truncated.Returns true if the computation was exact.
n must be positive.
-
root
Stores the n-th root of op into this, truncated, and the remainder op-this^n into r.n must be positive.
-
sqrt
Stores the truncated square root of op into this. -
sqrt
public void sqrt()Takes the truncated square root of this. -
sqrt
Stores the square root of op into this, truncated, and the remainder op-this^2 into r. -
isPerfectPower
public boolean isPerfectPower()Returns true if this has the form a^b for some a and b > 1.0 and 1 are perfect powers.
-
isPerfectSquare
public boolean isPerfectSquare()Returns true if this has the form a^2 for some a.0 and 1 are perfect squares.
-
isProbabPrime
public int isProbabPrime(int r) Returns 2 if this is definitely prime, 1 if it is probably prime, and 0 if it is definitely composite.r is the number of tests; high numbers increasing the certainty. A value between 5 and 10 is reasonable.
-
nextPrime
Stores into this the next prime greater than op.This uses a probabilistic algorithm so that the chance of getting a composite are non-null but extremely small.
-
gcd
Stores into this the greatest common divisor of op1 and op2.The result is always positive, even for negative inputs.
-
gcd
Returns the greatest common divisor of op1 and op2.this is unchanged.
op2 must be strictly positive.
-
gcd
Stores the greatest common divisor of op1 and op2 into this.Sets s and t to values such that s*op1+t*op2 = gcd and |s| <= |op2|, |t| <= |op1|.
-
lcm
Stores into this the least common multiple of op1 and op2. -
lcm
Stores into this the least common multiple of op1 and op2.op2 must be positive.
-
invert
Stores the inverse of op1 modulo op2 into this.Returns true if this inverse exists. Otherwise, returns false; this is undefined.
-
jacobi
Returns the Jacobi symbol of a and b.b must be odd.
-
legendre
Returns the Legendre symbol.p must be an odd positive prime.
-
kronecker
Returns the Jacobi symbol with the Kronecker extension. -
kronecker
Returns the Jacobi symbol with the Kronecker extension. -
kronecker
Returns the Jacobi symbol with the Kronecker extension. -
remove
Stores into this op with all occurrences of factor f removed.Returns the number of removed factors.
-
remove
Removes from this all occurrences of factor f.Returns the number of removed factors.
-
fac
public void fac(int op) Stores op! into this.op must be positive.
-
bin
Stores into this the binomial coefficient (n k).k must be positive.
-
bin
public void bin(int n, int k) Stores into this the binomial coefficient (n k).n and k must be positive.
-
fib
public void fib(int n) Stores into this the n-th Fibonacci number.n must be positive.
-
fib
Stores into this the n-th Fibonacci number, and into r the n-1-th Fibonacci number.n must be positive.
-
lucnum
public void lucnum(int n) Stores into this the n-th Lucas number.n must be positive.
-
lucnum
Stores into this the n-th Lucas number, and into r the n-1-th Lucas number.n must be positive.
-
cmp
Returns a positive, null, or negative number when this is respectively strictly greater, equal, or strictly smaller than op. -
cmp
public int cmp(int op) Returns a positive, null, or negative number when this is respectively strictly greater, equal, or strictly smaller than op. -
cmp
public int cmp(double op) Returns a positive, null, or negative number when this is respectively strictly greater, equal, or strictly smaller than op. -
cmpAbs
Returns a positive, null, or negative number when |this| is respectively strictly greater, equal, or strictly smaller than |op|. -
cmpAbs
public int cmpAbs(int op) Returns a positive, null, or negative number when |this| is respectively strictly greater, equal, or strictly smaller than |op|. -
cmpAbs
public int cmpAbs(double op) Returns a positive, null, or negative number when |this| is respectively strictly greater, equal, or strictly smaller than |op|. -
sgn
public int sgn()Returns +1, 0, or -1 when this is respectively strictly positive, null, or strictly negative. -
isEqual
Whether this and x have the same value. -
equals
Whether x is a Mpz and has the same value as this. -
compareTo
Compare the value of this and x.- Specified by:
compareTo
in interfaceComparable<Mpz>
-
hashCode
public int hashCode()Returns a hash of the value of this. -
isPhysicalEqual
Whether this and x have the same address in memory. -
and
Stores the bitwise and of op1 and op2 into this. -
and
Stores the bitwise and of this and op into this. -
or
Stores the bitwise or of op1 and op2 into this. -
or
Stores the bitwise or of this and op into this. -
xor
Stores the bitwise xor of op1 and op2 into this. -
xor
Stores the bitwise xor of this and op into this. -
not
Stores the bitwise complement of op into this. -
not
public void not()Stores the bitwise complement of this into this. -
popCount
public int popCount()Returns the number of bits set to 1 in this.Returns
infinite
if this is negative. -
hamDist
Returns the Hamming distance between this and op.Returns
infinite
if this and op have different signs. -
scan0
public int scan0(int pos) Returns the position of the first bit set to 0 at or after position pos.pos must be positive.
May return
infinite
, if this is negative. -
scan1
public int scan1(int pos) Returns the position of the first bit set to 1 at or after position pos.pos must be positive.
May return
infinite
, if this is positive. -
setBit
public void setBit(int pos) Sets the pos-th bit to 1 in this.pos must be positive.
-
clrBit
public void clrBit(int pos) Sets the pos-th bit to 0 in this.pos must be positive.
-
notBit
public void notBit(int pos) Inverts the pos-th bit in this.pos must be positive.
-
tstBit
public boolean tstBit(int pos) Returns true if the pos-th bit in this is 1.pos must be positive.
-
fitsInt
public boolean fitsInt()Whether this can fit in an int. -
isOdd
public boolean isOdd()Whether this is odd. -
isEven
public boolean isEven()Whether this is even. -
sizeInBase
public int sizeInBase(int b) Returns the number of digits necessary to represent |this| in base b. -
size
public int size()Returns the size (in GMP limbs) of the internal representation of this. -
randomBits
Stores into this a uniformly distributed random number with n bits (i.e., in 0..2^n-1).n must be positive.
-
random
Stores into this a uniformly distributed random number in 0..n-1. -
rRandomBits
Stores into this a random number with n bits, and long strings of zeros and ones in its binary representation.Useful to trigger corner-case bugs when testing.
-