Package it.unich.jgmp
Class MPZ
java.lang.Object
java.lang.Number
it.unich.jgmp.MPZ
- All Implemented Interfaces:
Serializable
,Comparable<MPZ>
Multi-precision integer number. This class encapsulates the
mpz_t
data type, see the
Integer
Functions page of the GMP manual. In determining the names and prototypes
of the methods of the MPZ
class, we adopt the rules described in the
documentation of the it.unich.jgmp
package, enriched with the
following ones:
- the functions in the categories I/O of Integers, Integer
Import and Export and Special Functions are not exposed by the
MPZ
class.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Cleaning action for theMPZ
class.static enum
Result enumeration for theisProbabPrime(int)
method. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate MpzT
The pointer to the nativempz_t
object.private static final long
Version for serializability. -
Constructor Summary
ConstructorsModifierConstructorDescriptionMPZ()
Build anMPZ
whose value is zero.MPZ
(double op) Build anMPZ
whose value is the truncation ofop
.MPZ
(long op) Build anMPZ
whose value isop
.Build anMPZ
whose value is the truncation ofop
.Build anMPZ
whose value is the truncation ofop
.Build anMPZ
whose value isop
.private
A private constructor which build anMPZ
starting from a pointer to its native data object.Build anMPZ
whose value is the number represented by the stringstr
in decimal base.Build anMPZ
whose value is the number represented by the stringstr
in the specifiedbase
.MPZ
(BigInteger op) Builds anMPZ
whose value is the same asop
. -
Method Summary
Modifier and TypeMethodDescriptionabs()
Return anMPZ
whose value is the absolute value ofthis
.Set thisMPZ
to its absolute value.Set thisMPZ
to the absolute value ofop
.Return anMPZ
whose value is(this + op)
.Set thisMPZ
to(this + op)
Set thisMPZ
to(op1 + op2)
.Return anMPZ
whose value is(this + op1 * op2)
.addmulAssign
(MPZ op1, MPZ op2) Add(op1 * op2)
to thisMPZ
.Return anMPZ
whose value is(this + op1 * op2)
.addmulUiAssign
(MPZ op1, long op2) Add(op1 * op2)
to thisMPZ
.addUi
(long op) Return anMPZ
whose value is(this + op)
.addUiAssign
(long op) Set thisMPZ
to(this + op)
addUiAssign
(MPZ op1, long op2) Set thisMPZ
to(op1 + op2)
.Return anMPZ
whose value is(this & op)
.Set thisMPZ
to(this & op)
.Set thisMPZ
to(op1 & op2)
.binUi
(long k) Return anMPZ
whose value is the binomial coefficientthis
overk
.binUiAssign
(long k) Set thisMPZ
to the binomial coefficientthis
overk
.binUiAssign
(MPZ n, long k) Set thisMPZ
to the binomial coefficientn
overk
.static MPZ
binUiUi
(long n, long k) Return anMPZ
whose value is the binomial coefficientn
overk
.binUiUiAssign
(long n, long k) Set thisMPZ
to the binomial coefficientn
overk
.bufferExport
(int order, int size, int endian, long nails) Return aByteBuffer
filled with word data from thisMPZ
.static MPZ
bufferImport
(int order, int size, int endian, long nails, ByteBuffer op) Return anMPZ
whose value is determined from the buffer of word data atop
.bufferImportAssign
(int order, int size, int endian, long nails, ByteBuffer op) Set thisMPZ
from the buffer of word data atop
.Return anMPZ
whose value is the quotient of the integer division(this / d)
, rounded towards +∞.cdivq2Exp
(long b) Return anMPZ
whose value is the quotient of the integer division(this / 2b)
, rounded towards +∞.cdivq2ExpAssign
(long b) Set thisMPZ
to the quotient of the integer division(this / 2b)
, rounded toward +∞.cdivq2ExpAssign
(MPZ n, long b) Set thisMPZ
to the quotient of the integer division(n / 2b)
, rounded toward +∞.cdivqAssign
(MPZ d) Set thisMPZ
to the quotient of the integer division(this / d)
, rounded towards +∞.cdivqAssign
(MPZ n, MPZ d) Set thisMPZ
to the quotient of the integer division(n / d)
, rounded towards +∞.Return a pair ofMPZ
s whose values are the quotient and remainder of the integer division(this / d)
, rounded towards +∞.cdivqrAssign
(MPZ r, MPZ d) Set thisMPZ
andr
to the quotient and remainder of the integer division(this / d)
, rounded towards +∞.cdivqrAssign
(MPZ r, MPZ n, MPZ d) Set thisMPZ
andr
to the quotient and remainder of the integer division(n / d)
, rounded towards +∞.long
cdivqrUiAssign
(MPZ r, long d) Set thisMPZ
andr
to the quotient and remainder of the integer division(this / d)
, rounded towards +∞; it also returns the remainder.long
cdivqrUiAssign
(MPZ r, MPZ n, long d) Set thisMPZ
andr
to the quotient and remainder of the integer division(n / d)
, rounded towards +∞; it also returns the remainder.long
cdivqUiAssign
(long d) Set thisMPZ
to the quotient of the integer division(this / d)
, rounded towards +∞; it also returns the remainder.long
cdivqUiAssign
(MPZ n, long d) Set thisMPZ
to the quotient of the integer division(n / d)
, rounded towards +∞; it also Return the remainder.Return anMPZ
whose value is the remainder of the integer division(this / d)
, rounded towards +∞.cdivr2Exp
(long b) Return anMPZ
whose value is the remainder of the integer division(this / 2b)
, rounded towards +∞.cdivr2ExpAssign
(long b) Set thisMPZ
to the remainder of the integer division(this / 2b)
, rounded toward +∞.cdivr2ExpAssign
(MPZ n, long b) Set thisMPZ
to the remainder of the integer division(n / 2b)
, rounded toward +∞.cdivrAssign
(MPZ d) Set thisMPZ
to the remainder of the integer division(this / d)
, rounded towards +∞.cdivrAssign
(MPZ n, MPZ d) Set thisMPZ
to the remainder of the integer division(n / d)
, rounded towards +∞.long
cdivrUiAssign
(long d) Set thisMPZ
to the remainder of the integer division(this / d)
, rounded towards +∞; it also returns the remainder.long
cdivrUiAssign
(MPZ n, long d) Set thisMPZ
to the remainder of the integer division(n / d)
, rounded towards +∞; it also returns the remainder.long
cdivUi
(long d) Return the remainder of the integer division(this / d)
, rounded towards +∞.clrbit
(long index) Return anMPZ
whose value is(this & ~ 2index)
.clrbitAssign
(long index) Clear the bitindex
of thisMPZ
.int
cmp
(double op) Comparethis
withop
.int
cmp
(long op) Comparethis
withop
.int
Comparethis
withop
.int
cmpabs
(double op) Compare the absolute values ofthis
andop
.int
Compare the absolute values ofthis
andop
.int
cmpabsUi
(long op) Compare the absolute values ofthis
andop
.int
cmpUi
(long op) Comparethis
withop
.com()
Return anMPZ
whose value is(~ op)
.Set thisMPZ
to(~ this)
.Set thisMPZ
to(~ op)
.combit
(long index) Return anMPZ
whose value is(this ^ 2index)
.combitAssign
(long index) Complement the bitindex
of thisMPZ
.int
Compare thisMPZ
withop
.static MPZ
dfacUi
(long n) Return anMPZ
whose value the double factorial ofn
.dfacUiAssign
(long n) Set thisMPZ
to the double factorial ofn
.Return anMPZ
whose value is the quotient of(this / d)
.Set thisMPZ
to the quotient of(this / d)
.divexactAssign
(MPZ n, MPZ d) Set thisMPZ
to the quotient of(n / d)
.divexactUi
(long d) Return anMPZ
whose value is the quotient of(this / d)
.divexactUiAssign
(long d) Set thisMPZ
to the quotient of(this / d)
.divexactUiAssign
(MPZ n, long d) Set thisMPZ
to the quotient of(n / d)
.double
Convert thisMPZ
to a double, truncating if necessary.boolean
Compare thisMPZ
with the objectop
for equality.static MPZ
facUi
(long n) Return anMPZ
whose value is the factorial ofn
.facUiAssign
(long n) Set thisMPZ
to the factorial ofn
.Return anMPZ
whose value is the quotient of the integer division(this / d)
, rounded towards -∞.fdivq2Exp
(long b) Return anMPZ
whose value is the quotient of the integer division(this / 2b)
, rounded towards -∞.fdivq2ExpAssign
(long b) Set thisMPZ
to the quotient of the integer division(this / 2b)
, rounded toward -∞.fdivq2ExpAssign
(MPZ n, long b) Set thisMPZ
to the quotient of the integer division(n / 2b)
, rounded toward -∞.fdivqAssign
(MPZ d) Set thisMPZ
to the quotient of the integer division(this / d)
, rounded towards -∞.fdivqAssign
(MPZ n, MPZ d) Set thisMPZ
to the quotient of the integer division(n / d)
, rounded towards -∞.Return twoMPZ
s whose values are the quotient and remainder of the integer division(this / d)
, rounded towards -∞.fdivqrAssign
(MPZ r, MPZ d) Set thisMPZ
andr
to the quotient and remainder of the integer division(this / d)
, rounded towards -∞.fdivqrAssign
(MPZ r, MPZ n, MPZ d) Set thisMPZ
andr
to the quotient and remainder of the integer division(n / d)
, rounded towards -∞.long
fdivqrUiAssign
(MPZ r, long d) Set thisMPZ
andr
to the quotient and remainder of the integer division(this / d)
, rounded towards -∞; it also returns the absolute value of the remainder.long
fdivqrUiAssign
(MPZ r, MPZ n, long d) Set thisMPZ
andr
to the quotient and remainder of the integer division(n / d)
, rounded towards -∞; it also returns the absolute value of the remainder.long
fdivqUiAssign
(long d) Set thisMPZ
to the quotient of the integer division(this / d)
, rounded towards -∞; it also returns the absolute value of the remainder.long
fdivqUiAssign
(MPZ n, long d) Set thisMPZ
to the quotient of the integer division(n / d)
, rounded towards -∞; it also returns the absolute value of the remainder.Return anMPZ
whose value is the remainder of the integer division(this / d)
, rounded towards -∞.fdivr2Exp
(long b) Return anMPZ
whose value is the remainder of the integer division(this / 2b)
, rounded towards -∞.fdivr2ExpAssign
(long b) Set thisMPZ
to the remainder of the integer division(this / 2b)
, rounded toward -∞.fdivr2ExpAssign
(MPZ n, long b) Set thisMPZ
to the remainder of the integer division(n / 2b)
, rounded toward -∞.fdivrAssign
(MPZ d) Set thisMPZ
to the remainder of the integer division(this / d)
, rounded towards -∞.fdivrAssign
(MPZ n, MPZ d) Set thisMPZ
to the remainder of the integer division(n / d)
, rounded towards -∞.long
fdivrUiAssign
(long d) Set thisMPZ
to the remainder of the integer division(this / d)
, rounded towards -∞; it also returns the absolute value of the remainder.long
fdivrUiAssign
(MPZ n, long d) Set thisMPZ
to the remainder of the integer division(n / d)
, rounded towards -∞; it also returns the absolute value of the remainder.long
fdivUi
(long d) Return the remainder of the integer division(this / d)
, rounded towards -∞.fib2Ui
(long n) Return twoMPZ
whose values are then
-th and(n-1)
-th Fibonacci numbers.fib2UiAssign
(MPZ fnsub1, long n) Set the value ofthis
andfnsub1
to then
-th and(n-1)
-th Fibonacci numbers respecively.static MPZ
fibUi
(long n) Return anMPZ
whose value is then
-th Fibonacci number.fibUiAssign
(long n) Set thisMPZ
to then
-th Fibonacci number.boolean
fitsSint()
Returntrue
if and only if thisMPZ
fits into a native signed int.boolean
Returntrue
if and only if thisMPZ
fits into a native signed long.boolean
Returntrue
if and only if thisMPZ
fits into a native signed short.boolean
fitsUint()
Returntrue
if and only if thisMPZ
fits into a native unsigned int.boolean
Returntrue
if and only if thisMPZ
fits into a native unsigned long.boolean
Returntrue
if and only if thisMPZ
fits into a native unsigned short.float
Convert thisMPZ
to a float, truncating if necessary.Return anMPZ
whose value is the greatest commond divisor ofthis
andop
.Set thisMPZ
to the greatest commond divisor ofthis
andop
.Set thisMPZ
to the greatest commond divisor ofop1
andop2
.Return the greatest common divisor ofthis
andop
, together with numberss
andt
satisfying(a*this + b*op = g)
See the GMP functionmpz_gcdext
.gcdextAssign
(MPZ s, MPZ t, MPZ op) Set thisMPZ
to the greatest common divisor ofthis
andop
, and in addition Sets
andt
to coefficients satisfying(this*s + op*t = gcd)
.gcdextAssign
(MPZ s, MPZ t, MPZ a, MPZ b) Set thisMPZ
to the greatest common divisor ofa
andb
, and in addition Sets
andt
to coefficients satisfying(a*s + b*t = gcd)
.long
gcdUi
(long op) Return the greatest commond divisor ofthis
andop
.long
gcdUiAssign
(long op) Set thisMPZ
to the greatest commond divisor ofop1
andop2
, and returns it.long
gcdUiAssign
(MPZ op1, long op2) Set thisMPZ
to the greatest commond divisor ofop1
andop2
, and return it.Converts thisMPZ
to BigInteger.double
getD()
Convert thisMPZ
to a double, truncating if necessary.getD2Exp()
Convert thisMPZ
to a pair made of mantissa and exponent, truncating if necessary.Return the native pointer to the GMP object.long
getSi()
Convert thisMPZ
to a signed long.getStr
(int base) Return the String representation of thisMPZ
in the specifiedbase
, ornull
if the base is not valid.long
getUi()
Convert thisMPZ
to an unsigned long.long
Ifthis
andop
are both>= 0
or both< 0
, return the Hamming distance between them, which is the number of bit positions wherethis
andop
have different bit values.int
hashCode()
Return a hash code value for thisMPZ
.static MPZ
init()
Return anMPZ
whose value is zero.static MPZ
init2
(long n) Return anMPZ
whose value is zero, with pre-allocated space forn
-bit numbers.static MPZ
initSet
(double op) Return anMPZ
whose value is the truncation ofop
.static MPZ
initSet
(long op) Return anMPZ
whose value isop
.static MPZ
Return anMPZ
whose value isop
.Return anMPZ
whose value is the number represented by the stringstr
in the specifiedbase
.static MPZ
initSetUi
(long op) Return anMPZ
whose value isop
.int
intValue()
Convert thisMPZ
to a signed int, truncating if necessary.Optionally return, when it exists, anMPZ
whose value is the inverse ofthis
moduloop
.boolean
invertAssign
(MPZ op) Set thisMPZ
to the inverse ofthis
moduloop
.boolean
invertAssign
(MPZ op1, MPZ op2) Set thisMPZ
to the inverse ofop1
moduloop2
.Return anMPZ
whose value is(this | op)
.Set thisMPZ
to(this | op)
.Set thisMPZ
to(op1 | op2)
.boolean
isCongruent
(MPZ c, MPZ d) Returntrue
if and only ifthis
is congruent toc
modulod
.boolean
isCongruent2Exp
(MPZ c, long b) Returntrue
if and only ifthis
is congruent toc
modulo2b
.boolean
isCongruentUi
(long c, long d) Returntrue
if and only ifthis
is congruent toc
modulod
.boolean
isDivisible
(MPZ d) Returntrue
if and only ifthis
is exactly divisible byd
.boolean
isDivisible2Exp
(long b) Returntrue
if and only ifthis
is exactly divisible by2b
.boolean
isDivisibleUi
(long d) Returntrue
if and only ifthis
is exactly divisible byd
.boolean
isEven()
Returntrue
if and only if thisMPZ
is evenboolean
isOdd()
Returntrue
if and only if thisMPZ
is odd.boolean
Returntrue
if and only if this number is a perfect power, i.e., if there exist integersa
andb
, with(b > 1)
, such thatthis
equals(ab)
.boolean
Returntrue
if and only if this number is a perfect square.isProbabPrime
(int reps) Returntrue
if and only ifthis
is prime.boolean
isZero()
Returntrue
if and only if thisMPZ
is zero.int
Return the Jacobi symbol(this / b)
.int
kronecker
(long b) Return the Jacobi symbol(this / b)
with the Kronecker extension.int
Return the Jacobi symbol(this / n)
with the Kronecker extension(this/2)=(2/this)
whenthis
is odd, or(this/2)=0
whenthis
is even.int
kroneckerReverse
(long a) Return the Jacobi symbol(a / this)
with the Kronecker extension.int
kroneckerUi
(long b) Return the Jacobi symbol(this / b)
with the Kronecker extension.Return anMPZ
whose value is the least common multiple ofthis
andop
.Set thisMPZ
to the least common multiple ofthis
andop
.Set thisMPZ
to the least common multiple ofop1
andop2
.lcmUi
(long op) Return the least common multiple ofthis
andop
.lcmUiAssign
(long op) Set thisMPZ
to the least common multiple ofthis
andop
.lcmUiAssign
(MPZ op1, long op2) Set thisMPZ
to the least common multiple ofop1
andop2
.int
Return the Legendre symbol(this / p)
.long
Convert thisMPZ
to a signed long.lucnum2Ui
(long n) Return twoMPZ
whose values are then
-th and(n-1)
-th Lucas numbers.lucnum2UiAssign
(MPZ fnsub1, long n) Set the value ofthis
andfnsub1
to then
-th and(n-1)
-th Lucas numbers respecively.static MPZ
lucnumUi
(long n) Return anMPZ
whose value is then
-th Lucas number.lucnumUiAssign
(long n) Set thisMPZ
to then
-th Lucas number.static MPZ
mfacUiUi
(long n, long m) Return anMPZ
whose value is them
-multi factorial ofn
.mfacUiUiAssign
(long n, long m) Set thisMPZ
to them
-multi factorial ofn
.Return anMPZ
whose value is(this mod d)
.Set thisMPZ
to(this mod d)
.Set thisMPZ
to(n mod d)
.long
modUi
(long d) Return anMPZ
whose value is(this mod d)
.long
modUiAssign
(long d) Set thisMPZ
to(n mod d)
; it also returns the result.long
modUiAssign
(MPZ n, long d) Set thisMPZ
to(n mod d)
; it also returns the result.mul
(long op) Return anMPZ
whose value is(this * op)
.Return anMPZ
whose value is(this * op)
.mul2Exp
(long b) Return anMPZ
whose value is(this * 2b)
.mul2ExpAssign
(long b) Set thisMPZ
to(this * 2b)
.mul2ExpAssign
(MPZ op, long b) Set thisMPZ
to(op * 2b)
.mulAssign
(long op) Set thisMPZ
to(this * op)
Set thisMPZ
to(this * op)
Set thisMPZ
to(op1 * op2)
.Set thisMPZ
to(op1 * op2)
.mulUi
(long op) Return anMPZ
whose value is(this * op)
.mulUiAssign
(long op) Set thisMPZ
to(this * op)
mulUiAssign
(MPZ op1, long op2) Set thisMPZ
to(op1 * op2)
.neg()
Return anMPZ
whose value is the quotient of(- this)
.Set thisMPZ
to its opposite.Set thisMPZ
to(- op)
.Return anMPZ
whose value is the next prime greater thenthis
.Set thisMPZ
to the next prime greater then itself.nextprimeAssign
(MPZ op) Set thisMPZ
to the next prime greater thenop
.long
popcount()
If thisMPZ
is non-negative, return its population count, which is the number of1
bits in its binary representation.Return anMPZ
whose value is(thisexp)
modulomod
.powmAssign
(MPZ exp, MPZ mod) Set thisMPZ
to(thisexp)
modulomod
.powmAssign
(MPZ base, MPZ exp, MPZ mod) Set thisMPZ
to(baseexp)
modulomod
.Return anMPZ
whose value is(thisexp)
modulomod
.powmSecAssign
(MPZ exp, MPZ mod) Set thisMPZ
to(thisexp)
modulomod
.powmSecAssign
(MPZ base, MPZ exp, MPZ mod) Set thisMPZ
to(baseexp)
modulomod
.Return anMPZ
whose value is(thisexp)
modulomod
.powmUiAssign
(long exp, MPZ mod) Set thisMPZ
to(thisexp)
modulomod
.powmUiAssign
(MPZ base, long exp, MPZ mod) Set thisMPZ
to(baseexp)
modulomod
.powUi
(long exp) Return anMPZ
whose value is(thisexp)
.static MPZ
powUi
(long base, long exp) Return anMPZ
whose value is(baseexp)
.powUiAssign
(long exp) Set thisMPZ
to(thisexp)
.powUiAssign
(long base, long exp) Set thisMPZ
to(baseexp)
.powUiAssign
(MPZ base, long exp) Set thisMPZ
to(baseexp)
.static MPZ
primorialUi
(long n) Return anMPZ
whose value is the primorial ofn
, i.e., the product of all positive prime numbers<= n
.primorialUiAssign
(long n) Set thisMPZ
to the primorial ofn
, i.e., the product of all positive prime numbers<= n
.static MPZ
random
(long max_size) Deprecated.static MPZ
random2
(long max_size) Deprecated.userrandomb(it.unich.jgmp.RandState,long)
instead, since this method uses a global random state and it is not reentrant.random2Assign
(long max_size) Deprecated.userrandombAssign(it.unich.jgmp.RandState,long)
instead, since this method uses a global random state and it is not reentrant.randomAssign
(long max_size) Deprecated.useurandombAssign(it.unich.jgmp.RandState,long)
orurandommAssign(it.unich.jgmp.RandState,it.unich.jgmp.MPZ)
instead, since this method uses a global random state and it is not reentrant.private void
private void
realloc2
(long n) Changes the space allocated for this number ton
bits.Return the result of removing the factorf
fromthis
, together with the number of occurrences which were removed.long
removeAssign
(MPZ f) Remove all occurrences of the factorf
fromthis
MPZ.long
removeAssign
(MPZ op, MPZ f) Remove all occurrences of the factorf
fromop
and stores the result in thisMPZ
.root
(long n) Return anMPZ
whose value is the truncated integer part of then
th root ofthis
, and a boolean flag which is true when the result is exact.boolean
rootAssign
(long n) Set thisMPZ
to the truncated integer part of itsn
th root.boolean
rootAssign
(MPZ op, long n) Set thisMPZ
to the truncated integer part of then
th root ofop
.rootrem
(long n) Return twoMPZ
s whose values are the truncated integer part of then
th root ofthis
and the remainder, i.e.,(u - rootn)
.rootremAssign
(MPZ rem, long n) Set thisMPZ
to the truncated integer part of the itsn
th root andrem
to the remainder, i.e.,(this - rootn)
.rootremAssign
(MPZ rem, MPZ u, long n) Set thisMPZ
to the truncated integer part of then
th root ofu
andrem
to the remainder, i.e.,(u - rootn)
.static MPZ
Return anMPZ
whose value is a random integer with long strings of zeros and ones in the binary representation.rrandombAssign
(RandState s, long n) Set thisMPZ
to a random integer with long strings of zeros and ones in the binary representation.long
scan0
(long starting_bit) Scan thisMPZ
, starting from bitstarting_bit
, towards more significant bits, until the first0
bit is found.long
scan1
(long starting_bit) Scanthis
, starting from bitstarting_bit
, towards more significant bits, until the first1
bit is found.set
(double op) Set thisMPZ
to the truncation ofop
.set
(long op) Set thisMPZ
toop
.Set thisMPZ
to the truncation ofop
.Set thisMPZ
to the truncation ofop
.Set thisMPZ
toop
.(package private) static void
set
(MpzT mpzNative, BigInteger op) int
Set thisMPZ
to the number represented by the stringstr
in the specifiedbase
.set
(BigInteger op) Sets thisMPZ
toop
.setbit
(long index) Return anMPZ
whose value is(this | 2index)
.setbitAssign
(long index) Set the bitindex
of thisMPZ
.setUi
(long op) Set thisMPZ
toop
.setValue
(double op) Set thisMPZ
to the truncation opop
.setValue
(long op) Set thisMPZ
to signed longop
.Set thisMPZ
to the truncation opop
.Set thisMPZ
to the truncation opop
.Set thisMPZ
toop
.Set thisMPZ
to the value represented by the stringstr
in decimal base.Set thisMPZ
to the number represented by the stringstr
in the specifiedbase
.setValue
(BigInteger op) Sets thisMPZ
toop
.int
sgn()
Return+1
if(this > 0)
,0
if(this = 0)
and-1
ifthis < 0
.long
sizeinbase
(int base) Return the size of thisMPZ
measured in number of digits in the specifiedbase
.sqrt()
Return anMPZ
whose value is the truncated integer part of the square root ofthis
.Set thisMPZ
to the truncated integer part of its square root.sqrtAssign
(MPZ op) Set thisMPZ
to the truncated integer part of the square root ofop
.sqrtrem()
Return twoMPZ
s whose values are the truncated integer part of the square root ofthis
and the remainder, i.e.,(op - root2)
.sqrtremAssign
(MPZ rem) Set thisMPZ
to the truncated integer part of its square root andrem
to the remainder, i.e.,(this - root2)
.sqrtremAssign
(MPZ rem, MPZ op) Set thisMPZ
to the truncated integer part of the square root ofop
andrem
to the remainder, i.e.,(op - root2)
.Return anMPZ
whose value is(this - op)
.Set thisMPZ
to(this - op)
Set thisMPZ
to(op1 - op2)
.Return anMPZ
whose value is(this - op1 * op2)
.submulAssign
(MPZ op1, MPZ op2) Subtract(op1 * op2)
to thisMPZ
.Return anMPZ
whose value is(this - op1 * op2)
.submulUiAssign
(MPZ op1, long op2) Subtract(op1 * op2)
to thisMPZ
.subUi
(long op) Return anMPZ
whose value is(this - op)
.subUiAssign
(long op) Set thisMPZ
to(this - op)
subUiAssign
(MPZ op1, long op2) Set thisMPZ
to(op1 - op2)
.Swap the value of thisMPZ
with the value ofop
.Return anMPZ
whose value is the quotient of the integer division(this / d)
, rounded towards zero.tdivq2Exp
(long b) Return anMPZ
whose value is the quotient of the integer division(this / 2b)
, rounded towards zero.tdivq2ExpAssign
(long b) Set thisMPZ
to the quotient of the integer division(this / 2b)
, rounded toward zero.tdivq2ExpAssign
(MPZ n, long b) Set thisMPZ
to the quotient of the integer division(n / 2b)
, rounded toward zero.tdivqAssign
(MPZ d) Set thisMPZ
to the quotient of the integer division(this / d)
, rounded towards zero.tdivqAssign
(MPZ n, MPZ d) Set thisMPZ
to the quotient of the integer division(n / d)
, rounded towards zero.Return twoMPZ
s whose values are the quotient and remainder of the integer division(this / d)
, rounded towards zero.tdivqrAssign
(MPZ r, MPZ d) Set thisMPZ
andr
to the quotient and remainder of the integer division(this / d)
, rounded towards zero.tdivqrAssign
(MPZ r, MPZ n, MPZ d) Set thisMPZ
andr
to the quotient and remainder of the integer division(n / d)
, rounded towards zero.long
tdivqrUiAssign
(MPZ r, long d) Set thisMPZ
andr
to the quotient and remainder of the integer division(this / d)
, rounded towards zero; it also returns the absolute value of the remainder.long
tdivqrUiAssign
(MPZ r, MPZ n, long d) Set thisMPZ
andr
to the quotient and remainder of the integer division(n / d)
, rounded towards zero; it also returns the absolute value of the remainder.long
tdivqUiAssign
(long d) Set thisMPZ
to the quotient of the integer division(this / d)
, rounded towards zero; it also returns the absolute value of the remainder.long
tdivqUiAssign
(MPZ n, long d) Set thisMPZ
to the quotient of the integer division(n / d)
, rounded towards zero; it also returns the absolute value of the remainder.Return anMPZ
whose value is the remainder of the integer division(this / d)
, rounded towards zero.tdivr2Exp
(long b) Return anMPZ
whose value is the remainder of the integer division(this / 2b)
, rounded towards zero.tdivr2ExpAssign
(long b) Set thisMPZ
to the remainder of the integer division(this / 2b)
, rounded toward zero.tdivr2ExpAssign
(MPZ n, long b) Set thisMPZ
to the remainder of the integer division(n / 2b)
, rounded toward zero.tdivrAssign
(MPZ d) Set thisMPZ
to the remainder of the integer division(this / d)
, rounded towards zero.tdivrAssign
(MPZ n, MPZ d) Set thisMPZ
to the remainder of the integer division(n / d)
, rounded towards zero.long
tdivrUiAssign
(long d) Set thisMPZ
to the remainder of the integer division(this / d)
, rounded towards zero; it also returns the absolute value of the remainder.long
tdivrUiAssign
(MPZ n, long d) Set thisMPZ
to the remainder of the integer division(n / d)
, rounded towards zero; it also returns the absolute value of the remainder.long
tdivUi
(long d) Return the remainder of the integer division(this / d)
, rounded towards zero.toString()
Convert thisMPZ
to its decimal string representation.toString
(int base) Convert thisMPZ
to its string representation in the specifiedbase
, ornull
if the base is not valid.int
tstbit
(long index) Return the bitindex
of thisMPZ
.int
uiKronecker
(long a) Return the Jacobi symbol(a / this)
with the Kronecker extension.uiSub
(long op) Return anMPZ
whose value is(op - this)
.uiSubAssign
(long op) Set thisMPZ
to(op - this)
uiSubAssign
(long op1, MPZ op2) Set thisMPZ
to(op1 - op2)
.static MPZ
Return anMPZ
whose value is an uniformly distributed random integer in the range0
} to(2n - 1)
, inclusive.urandombAssign
(RandState s, long n) Set thisMPZ
to a uniformly distributed random integer in the range0
to(2n - 1)
, inclusive.static MPZ
Return anMPZ
whose value is an uniformly distributed random integer in the range0
to(n - 1)
, inclusive.urandommAssign
(RandState s, MPZ n) Set thisMPZ
to a uniformly distributed random integer in the range0
to(n - 1)
, inclusive.private void
Return anMPZ
whose value is(this ^ op)
.Set thisMPZ
to(this ^ op)
.Set thisMPZ
to(op1 ^ op2)
.Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDVersion for serializability.- See Also:
-
mpzNative
The pointer to the nativempz_t
object.
-
-
Constructor Details
-
MPZ
A private constructor which build anMPZ
starting from a pointer to its native data object. The native object needs to be already initialized. -
MPZ
public MPZ()Build anMPZ
whose value is zero. -
MPZ
Build anMPZ
whose value isop
. -
MPZ
public MPZ(long op) Build anMPZ
whose value isop
. -
MPZ
public MPZ(double op) Build anMPZ
whose value is the truncation ofop
.- Throws:
ArithmeticException
- ifop
is not a finite number.
-
MPZ
Build anMPZ
whose value is the truncation ofop
. -
MPZ
Build anMPZ
whose value is the truncation ofop
. -
MPZ
Build anMPZ
whose value is the number represented by the stringstr
in the specifiedbase
. See the GMP functionmpz_init_set_str
.- Throws:
NumberFormatException
- if eitherbase
is not valid orstr
is not a valid string in the specifiedbase
.
-
MPZ
Build anMPZ
whose value is the number represented by the stringstr
in decimal base. See the GMP functionmpz_init_set_str
.- Throws:
NumberFormatException
- ifstr
is not a valid number representation in decimal base.
-
MPZ
Builds anMPZ
whose value is the same asop
.
-
-
Method Details
-
getNative
Return the native pointer to the GMP object. -
init
Return anMPZ
whose value is zero. -
init2
Return anMPZ
whose value is zero, with pre-allocated space forn
-bit numbers. Calling this method is never necessary; reallocation is handled automatically by GMP when needed. See the GMP functionmpz_init2
. -
realloc2
Changes the space allocated for this number ton
bits. The value is preserved if it fits, otherwise it is set to 0. Calling this function is never necessary; reallocation is handled automatically by GMP when needed. This function can be used to increase the space for a variable in order to avoid repeated automatic reallocations, or to decrease it to give memory back to the heap.- Returns:
- this
MPZ
.
-
set
Set thisMPZ
toop
.- Returns:
- this
MPZ
.
-
set
Set thisMPZ
toop
.- Returns:
- this
MPZ
.
-
setUi
Set thisMPZ
toop
.- Returns:
- this
MPZ
.
-
set
Set thisMPZ
to the truncation ofop
.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifop
is not a finite number. In this case,this
is not altered.
-
set
Set thisMPZ
to the truncation ofop
.- Returns:
- this
MPZ
.
-
set
Set thisMPZ
to the truncation ofop
.- Returns:
- this
MPZ
.
-
set
Set thisMPZ
to the number represented by the stringstr
in the specifiedbase
. See the GMP functionmpz_set_str
.- Returns:
- 0 if the operation succeeded, -1 otherwise. In the latter case,
this
is not altered.
-
set
-
set
Sets thisMPZ
toop
.- Returns:
- this
MPZ
.
-
swap
Swap the value of thisMPZ
with the value ofop
.- Returns:
- this
MPZ
.
-
initSet
Return anMPZ
whose value isop
. -
initSet
Return anMPZ
whose value isop
. -
initSetUi
Return anMPZ
whose value isop
. -
initSet
Return anMPZ
whose value is the truncation ofop
.- Throws:
ArithmeticException
- ifop
is not a finite number.
-
initSet
Return anMPZ
whose value is the number represented by the stringstr
in the specifiedbase
. See the GMP functionmpz_init_set_str
.- Returns:
- a pair whose first component is
0
if the operation succeeded, and-1
if eitherbase
is not valid, orstr
is not a valid numeric representation in the specified base. The second component of the pair is the number represented instr
if the operation succeeded,0
otherwise.
-
getUi
public long getUi()Convert thisMPZ
to an unsigned long. If this number is too big to fit a native unsigned long, then just the least significant bits that do fit are returned. The sign of this number is ignored, only the absolute value is used. -
getSi
public long getSi()Convert thisMPZ
to a signed long. If this number is too big to fit a native signed long, return the least significant part, preserving the sign. -
getD
public double getD()Convert thisMPZ
to a double, truncating if necessary. If the exponent from the conversion is too big, the result is system dependent. An infinity is returned where available. A hardware overflow trap may or may not occur. -
getD2Exp
Convert thisMPZ
to a pair made of mantissa and exponent, truncating if necessary. See the GMP functionmpz_get_d_2exp
. -
getStr
Return the String representation of thisMPZ
in the specifiedbase
, ornull
if the base is not valid. See the GMP functionmpz_get_str
. -
getBigInteger
Converts thisMPZ
to BigInteger. -
addAssign
Set thisMPZ
to(op1 + op2)
.- Returns:
- this
MPZ
.
-
addAssign
Set thisMPZ
to(this + op)
- Returns:
- this
MPZ
-
add
Return anMPZ
whose value is(this + op)
. -
addUiAssign
Set thisMPZ
to(op1 + op2)
.- Returns:
- this
MPZ
.
-
addUiAssign
Set thisMPZ
to(this + op)
- Returns:
- this
MPZ
-
addUi
Return anMPZ
whose value is(this + op)
. -
subAssign
Set thisMPZ
to(op1 - op2)
.- Returns:
- this
MPZ
.
-
subAssign
Set thisMPZ
to(this - op)
- Returns:
- this
MPZ
-
sub
Return anMPZ
whose value is(this - op)
. -
subUiAssign
Set thisMPZ
to(op1 - op2)
.- Returns:
- this
MPZ
.
-
subUiAssign
Set thisMPZ
to(this - op)
- Returns:
- this
MPZ
-
subUi
Return anMPZ
whose value is(this - op)
. -
uiSubAssign
Set thisMPZ
to(op1 - op2)
.- Returns:
- this
MPZ
.
-
uiSubAssign
Set thisMPZ
to(op - this)
- Returns:
- this
MPZ
-
uiSub
Return anMPZ
whose value is(op - this)
. -
mulAssign
Set thisMPZ
to(op1 * op2)
.- Returns:
- this
MPZ
.
-
mulAssign
Set thisMPZ
to(this * op)
- Returns:
- this
MPZ
-
mul
Return anMPZ
whose value is(this * op)
. -
mulUiAssign
Set thisMPZ
to(op1 * op2)
.- Returns:
- this
MPZ
.
-
mulUiAssign
Set thisMPZ
to(this * op)
- Returns:
- this
MPZ
-
mulUi
Return anMPZ
whose value is(this * op)
. -
mulAssign
Set thisMPZ
to(op1 * op2)
.- Returns:
- this
MPZ
.
-
mulAssign
Set thisMPZ
to(this * op)
- Returns:
- this
MPZ
-
mul
Return anMPZ
whose value is(this * op)
. -
addmulAssign
Add(op1 * op2)
to thisMPZ
.- Returns:
- this
MPZ
.
-
addmul
Return anMPZ
whose value is(this + op1 * op2)
. -
addmulUiAssign
Add(op1 * op2)
to thisMPZ
.- Returns:
- this
MPZ
.
-
addmulUi
Return anMPZ
whose value is(this + op1 * op2)
. -
submulAssign
Subtract(op1 * op2)
to thisMPZ
.- Returns:
- this
MPZ
.
-
submul
Return anMPZ
whose value is(this - op1 * op2)
. -
submulUiAssign
Subtract(op1 * op2)
to thisMPZ
.- Returns:
- this
MPZ
.
-
submulUi
Return anMPZ
whose value is(this - op1 * op2)
. -
mul2ExpAssign
Set thisMPZ
to(op * 2b)
.- Returns:
- this
MPZ
.
-
mul2ExpAssign
Set thisMPZ
to(this * 2b)
.- Returns:
- this
MPZ
.
-
mul2Exp
Return anMPZ
whose value is(this * 2b)
. -
negAssign
Set thisMPZ
to(- op)
.- Returns:
- this
MPZ
.
-
negAssign
Set thisMPZ
to its opposite.- Returns:
- this
MPZ
.
-
neg
Return anMPZ
whose value is the quotient of(- this)
. -
absAssign
Set thisMPZ
to the absolute value ofop
.- Returns:
- this
MPZ
.
-
absAssign
Set thisMPZ
to its absolute value.- Returns:
- this
MPZ
.
-
abs
Return anMPZ
whose value is the absolute value ofthis
. -
cdivqAssign
Set thisMPZ
to the quotient of the integer division(n / d)
, rounded towards +∞.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
cdivqAssign
Set thisMPZ
to the quotient of the integer division(this / d)
, rounded towards +∞.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
cdivrAssign
Set thisMPZ
to the remainder of the integer division(n / d)
, rounded towards +∞.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
cdivrAssign
Set thisMPZ
to the remainder of the integer division(this / d)
, rounded towards +∞.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
cdivqrAssign
Set thisMPZ
andr
to the quotient and remainder of the integer division(n / d)
, rounded towards +∞.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.IllegalArgumentException
- ifthis
andr
are the same object.
-
cdivqrAssign
Set thisMPZ
andr
to the quotient and remainder of the integer division(this / d)
, rounded towards +∞.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.IllegalArgumentException
- ifthis
andr
are the same object.
-
cdivqUiAssign
Set thisMPZ
to the quotient of the integer division(n / d)
, rounded towards +∞; it also Return the remainder.- Throws:
ArithmeticException
- ifd
is zero.
-
cdivqUiAssign
public long cdivqUiAssign(long d) Set thisMPZ
to the quotient of the integer division(this / d)
, rounded towards +∞; it also returns the remainder.- Throws:
ArithmeticException
- ifd
is zero.
-
cdivrUiAssign
Set thisMPZ
to the remainder of the integer division(n / d)
, rounded towards +∞; it also returns the remainder.- Throws:
ArithmeticException
- ifd
is zero.
-
cdivrUiAssign
public long cdivrUiAssign(long d) Set thisMPZ
to the remainder of the integer division(this / d)
, rounded towards +∞; it also returns the remainder.- Throws:
ArithmeticException
- ifd
is zero.
-
cdivqrUiAssign
Set thisMPZ
andr
to the quotient and remainder of the integer division(n / d)
, rounded towards +∞; it also returns the remainder.- Throws:
ArithmeticException
- ifd
is zero.IllegalArgumentException
- ifthis
andr
are the same object.
-
cdivqrUiAssign
Set thisMPZ
andr
to the quotient and remainder of the integer division(this / d)
, rounded towards +∞; it also returns the remainder.- Throws:
ArithmeticException
- ifd
is zero.IllegalArgumentException
- ifthis
andr
are the same object.
-
cdivUi
public long cdivUi(long d) Return the remainder of the integer division(this / d)
, rounded towards +∞.- Throws:
ArithmeticException
- ifd
is zero.
-
cdivq2ExpAssign
Set thisMPZ
to the quotient of the integer division(n / 2b)
, rounded toward +∞.- Returns:
- this
MPZ
.
-
cdivq2ExpAssign
Set thisMPZ
to the quotient of the integer division(this / 2b)
, rounded toward +∞.- Returns:
- this
MPZ
.
-
cdivr2ExpAssign
Set thisMPZ
to the remainder of the integer division(n / 2b)
, rounded toward +∞.- Returns:
- this
MPZ
.
-
cdivr2ExpAssign
Set thisMPZ
to the remainder of the integer division(this / 2b)
, rounded toward +∞.- Returns:
- this
MPZ
.
-
cdivq
Return anMPZ
whose value is the quotient of the integer division(this / d)
, rounded towards +∞.- Throws:
ArithmeticException
- ifd
is zero.
-
cdivr
Return anMPZ
whose value is the remainder of the integer division(this / d)
, rounded towards +∞.- Throws:
ArithmeticException
- ifd
is zero.
-
cdivqr
Return a pair ofMPZ
s whose values are the quotient and remainder of the integer division(this / d)
, rounded towards +∞.- Throws:
ArithmeticException
- ifd
is zero.
-
cdivq2Exp
Return anMPZ
whose value is the quotient of the integer division(this / 2b)
, rounded towards +∞. -
cdivr2Exp
Return anMPZ
whose value is the remainder of the integer division(this / 2b)
, rounded towards +∞. -
fdivqAssign
Set thisMPZ
to the quotient of the integer division(n / d)
, rounded towards -∞.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
fdivqAssign
Set thisMPZ
to the quotient of the integer division(this / d)
, rounded towards -∞.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
fdivrAssign
Set thisMPZ
to the remainder of the integer division(n / d)
, rounded towards -∞.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
fdivrAssign
Set thisMPZ
to the remainder of the integer division(this / d)
, rounded towards -∞.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
fdivqrAssign
Set thisMPZ
andr
to the quotient and remainder of the integer division(n / d)
, rounded towards -∞.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.IllegalArgumentException
- ifthis
andr
are the same object.
-
fdivqrAssign
Set thisMPZ
andr
to the quotient and remainder of the integer division(this / d)
, rounded towards -∞.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.IllegalArgumentException
- ifthis
andr
are the same object.
-
fdivqUiAssign
Set thisMPZ
to the quotient of the integer division(n / d)
, rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
ArithmeticException
- ifd
is zero.
-
fdivqUiAssign
public long fdivqUiAssign(long d) Set thisMPZ
to the quotient of the integer division(this / d)
, rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
ArithmeticException
- ifd
is zero.
-
fdivrUiAssign
Set thisMPZ
to the remainder of the integer division(n / d)
, rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
ArithmeticException
- ifd
is zero.
-
fdivrUiAssign
public long fdivrUiAssign(long d) Set thisMPZ
to the remainder of the integer division(this / d)
, rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
ArithmeticException
- ifd
is zero.
-
fdivqrUiAssign
Set thisMPZ
andr
to the quotient and remainder of the integer division(n / d)
, rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
ArithmeticException
- ifd
is zero.IllegalArgumentException
- ifthis
andr
are the same object.
-
fdivqrUiAssign
Set thisMPZ
andr
to the quotient and remainder of the integer division(this / d)
, rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
ArithmeticException
- ifd
is zero.IllegalArgumentException
- ifthis
andr
are the same object.
-
fdivUi
public long fdivUi(long d) Return the remainder of the integer division(this / d)
, rounded towards -∞.- Throws:
ArithmeticException
- ifd
is zero.
-
fdivq2ExpAssign
Set thisMPZ
to the quotient of the integer division(n / 2b)
, rounded toward -∞.- Returns:
- this
MPZ
.
-
fdivq2ExpAssign
Set thisMPZ
to the quotient of the integer division(this / 2b)
, rounded toward -∞.- Returns:
- this
MPZ
.
-
fdivr2ExpAssign
Set thisMPZ
to the remainder of the integer division(n / 2b)
, rounded toward -∞.- Returns:
- this
MPZ
.
-
fdivr2ExpAssign
Set thisMPZ
to the remainder of the integer division(this / 2b)
, rounded toward -∞.- Returns:
- this
MPZ
.
-
fdivq
Return anMPZ
whose value is the quotient of the integer division(this / d)
, rounded towards -∞.- Throws:
ArithmeticException
- ifd
is zero.
-
fdivr
Return anMPZ
whose value is the remainder of the integer division(this / d)
, rounded towards -∞.- Throws:
ArithmeticException
- ifd
is zero.
-
fdivqr
Return twoMPZ
s whose values are the quotient and remainder of the integer division(this / d)
, rounded towards -∞.- Throws:
ArithmeticException
- ifd
is zero.
-
fdivq2Exp
Return anMPZ
whose value is the quotient of the integer division(this / 2b)
, rounded towards -∞. -
fdivr2Exp
Return anMPZ
whose value is the remainder of the integer division(this / 2b)
, rounded towards -∞. -
tdivqAssign
Set thisMPZ
to the quotient of the integer division(n / d)
, rounded towards zero.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
tdivqAssign
Set thisMPZ
to the quotient of the integer division(this / d)
, rounded towards zero.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
tdivrAssign
Set thisMPZ
to the remainder of the integer division(n / d)
, rounded towards zero.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
tdivrAssign
Set thisMPZ
to the remainder of the integer division(this / d)
, rounded towards zero.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
tdivqrAssign
Set thisMPZ
andr
to the quotient and remainder of the integer division(n / d)
, rounded towards zero.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.IllegalArgumentException
- ifthis
andr
are the same object.
-
tdivqrAssign
Set thisMPZ
andr
to the quotient and remainder of the integer division(this / d)
, rounded towards zero.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.IllegalArgumentException
- ifthis
andr
are the same object.
-
tdivqUiAssign
Set thisMPZ
to the quotient of the integer division(n / d)
, rounded towards zero; it also returns the absolute value of the remainder.- Throws:
ArithmeticException
- ifd
is zero.
-
tdivqUiAssign
public long tdivqUiAssign(long d) Set thisMPZ
to the quotient of the integer division(this / d)
, rounded towards zero; it also returns the absolute value of the remainder.- Throws:
ArithmeticException
- ifd
is zero.
-
tdivrUiAssign
Set thisMPZ
to the remainder of the integer division(n / d)
, rounded towards zero; it also returns the absolute value of the remainder.- Throws:
ArithmeticException
- ifd
is zero.
-
tdivrUiAssign
public long tdivrUiAssign(long d) Set thisMPZ
to the remainder of the integer division(this / d)
, rounded towards zero; it also returns the absolute value of the remainder.- Throws:
ArithmeticException
- ifd
is zero.
-
tdivqrUiAssign
Set thisMPZ
andr
to the quotient and remainder of the integer division(n / d)
, rounded towards zero; it also returns the absolute value of the remainder.- Throws:
ArithmeticException
- ifd
is zero.IllegalArgumentException
- ifthis
andr
are the same object.
-
tdivqrUiAssign
Set thisMPZ
andr
to the quotient and remainder of the integer division(this / d)
, rounded towards zero; it also returns the absolute value of the remainder.- Throws:
ArithmeticException
- ifd
is zero.IllegalArgumentException
- ifthis
andr
are the same object.
-
tdivUi
public long tdivUi(long d) Return the remainder of the integer division(this / d)
, rounded towards zero.- Throws:
ArithmeticException
- ifd
is zero.
-
tdivq2ExpAssign
Set thisMPZ
to the quotient of the integer division(n / 2b)
, rounded toward zero.- Returns:
- this
MPZ
.
-
tdivq2ExpAssign
Set thisMPZ
to the quotient of the integer division(this / 2b)
, rounded toward zero.- Returns:
- this
MPZ
.
-
tdivr2ExpAssign
Set thisMPZ
to the remainder of the integer division(n / 2b)
, rounded toward zero.- Returns:
- this
MPZ
.
-
tdivr2ExpAssign
Set thisMPZ
to the remainder of the integer division(this / 2b)
, rounded toward zero.- Returns:
- this
MPZ
.
-
tdivq
Return anMPZ
whose value is the quotient of the integer division(this / d)
, rounded towards zero.- Throws:
ArithmeticException
- ifd
is zero.
-
tdivr
Return anMPZ
whose value is the remainder of the integer division(this / d)
, rounded towards zero.- Throws:
ArithmeticException
- ifd
is zero.
-
tdivqr
Return twoMPZ
s whose values are the quotient and remainder of the integer division(this / d)
, rounded towards zero.- Throws:
ArithmeticException
- ifd
is zero.
-
tdivq2Exp
Return anMPZ
whose value is the quotient of the integer division(this / 2b)
, rounded towards zero. -
tdivr2Exp
Return anMPZ
whose value is the remainder of the integer division(this / 2b)
, rounded towards zero. -
modAssign
Set thisMPZ
to(n mod d)
. The sign of the divisor is ignored, the result is always non-negative.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
modAssign
Set thisMPZ
to(this mod d)
. The sign of the divisor is ignored, the result is always non-negative.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
mod
Return anMPZ
whose value is(this mod d)
. The sign of the divisor is ignored, the result is always non-negative. -
modUiAssign
Set thisMPZ
to(n mod d)
; it also returns the result. The sign of the divisor is ignored, the result is always non-negative.- Throws:
ArithmeticException
- ifd
is zero.
-
modUiAssign
public long modUiAssign(long d) Set thisMPZ
to(n mod d)
; it also returns the result. The sign of the divisor is ignored, the result is always non-negative.- Throws:
ArithmeticException
- ifd
is zero.
-
modUi
public long modUi(long d) Return anMPZ
whose value is(this mod d)
. The sign of the divisor is ignored, the result is always non-negative.- Throws:
ArithmeticException
- ifd
is zero.
-
divexactAssign
Set thisMPZ
to the quotient of(n / d)
. This method produces correct results only when it is known in advance thatd
dividesn
.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
divexactAssign
Set thisMPZ
to the quotient of(this / d)
. This method produces correct results only when it is known in advance thatd
dividesthis
.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
divexact
Return anMPZ
whose value is the quotient of(this / d)
. This method produces correct results only when it is known in advance thatd
dividesthis
.- Throws:
ArithmeticException
- ifd
is zero.
-
divexactUiAssign
Set thisMPZ
to the quotient of(n / d)
. This method produces correct results only when it is known in advance thatd
dividesn
.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
divexactUiAssign
Set thisMPZ
to the quotient of(this / d)
. This method produces correct results only when it is known in advance thatd
dividesthis
.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifd
is zero.
-
divexactUi
Return anMPZ
whose value is the quotient of(this / d)
. This method produces correct results only when it is known in advance thatd
dividesthis
.- Throws:
ArithmeticException
- ifd
is zero.
-
isDivisible
Returntrue
if and only ifthis
is exactly divisible byd
. This means that there exists an integerq
satisfying(n = q*d)
. Unlike the other division functions, the cased=0
is accepted and following the rule it can be seen that only0
is considered divisible by0
. -
isDivisibleUi
public boolean isDivisibleUi(long d) Returntrue
if and only ifthis
is exactly divisible byd
. This means that there exists an integerq
satisfying(n = q*d)
. The cased=0
is accepted and following the rule it can be seen that only0
is considered divisible by0
. -
isDivisible2Exp
public boolean isDivisible2Exp(long b) Returntrue
if and only ifthis
is exactly divisible by2b
. This means that there exists an integerq
satisfying(n = q * 2^b)
. -
isCongruent
Returntrue
if and only ifthis
is congruent toc
modulod
. This means that there exists an integerq
satisfying(n = c + q*d)
. Unlike the other division functions,d=0
is accepted and following the rule it can be seen thatn
andc
are considered congruent modulo0
only when exactly equal. -
isCongruentUi
public boolean isCongruentUi(long c, long d) Returntrue
if and only ifthis
is congruent toc
modulod
. This means that there exists an integerq
satisfying(n = c + q*d)
. Unlike the other division functions,d=0
is accepted and following the rule it can be seen thatn
andc
are considered congruent modulo0
only when exactly equal. -
isCongruent2Exp
Returntrue
if and only ifthis
is congruent toc
modulo2b
. This means that there exists an integerq
satisfying(n = c + q*2^b)
. -
powmAssign
Set thisMPZ
to(baseexp)
modulomod
. Negativeexp
is supported if the inverse ofbase
modulomod
exists, otherwise anArithmeticExpection
is thrown.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifmod
is zero orbase
has no inverse modulomod
.
-
powmAssign
Set thisMPZ
to(thisexp)
modulomod
.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifmod
is zero.
-
powm
Return anMPZ
whose value is(thisexp)
modulomod
. -
powmUiAssign
Set thisMPZ
to(baseexp)
modulomod
.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifmod
is zero.
-
powmUiAssign
Set thisMPZ
to(thisexp)
modulomod
.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifmod
is zero.
-
powmUi
Return anMPZ
whose value is(thisexp)
modulomod
. -
powmSecAssign
Set thisMPZ
to(baseexp)
modulomod
. It is required that(exp > 0
and thatmod
is odd. This function is intended for cryptographic purposes, where resilience to side-channel attacks is desired.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifmod
is even orexp
is negative.
-
powmSecAssign
Set thisMPZ
to(thisexp)
modulomod
. It is required that(exp > 0
and thatmod
is odd. This function is intended for cryptographic purposes, where resilience to side-channel attacks is desired.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifmod
is zero.
-
powmSec
Return anMPZ
whose value is(thisexp)
modulomod
. It is required that(exp > 0)
and thatmod
is odd. This function is intended for cryptographic purposes, where resilience to side-channel attacks is desired. -
powUiAssign
Set thisMPZ
to(baseexp)
. The case00
yields1
.- Returns:
- this
MPZ
.
-
powUiAssign
Set thisMPZ
to(thisexp)
. The case00
yields1
.- Returns:
- this
MPZ
.
-
powUi
Return anMPZ
whose value is(thisexp)
. The case00
yields1
. -
powUiAssign
Set thisMPZ
to(baseexp)
. The case00
yields1
.- Returns:
- this
MPZ
.
-
powUi
Return anMPZ
whose value is(baseexp)
. The case00
yields1
. -
rootAssign
Set thisMPZ
to the truncated integer part of then
th root ofop
.- Returns:
- true if the computation is exact.
- Throws:
ArithmeticException
- if n is even and op is negative.
-
rootAssign
public boolean rootAssign(long n) Set thisMPZ
to the truncated integer part of itsn
th root.- Returns:
- true if the computation is exact.
- Throws:
ArithmeticException
- if n is even and this is negative.
-
root
Return anMPZ
whose value is the truncated integer part of then
th root ofthis
, and a boolean flag which is true when the result is exact.- Throws:
ArithmeticException
- if n is even and this is negative.
-
rootremAssign
Set thisMPZ
to the truncated integer part of then
th root ofu
andrem
to the remainder, i.e.,(u - rootn)
.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- if n is even and u is negative.
-
rootremAssign
Set thisMPZ
to the truncated integer part of the itsn
th root andrem
to the remainder, i.e.,(this - rootn)
.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- if n is even and this is negative.
-
rootrem
Return twoMPZ
s whose values are the truncated integer part of then
th root ofthis
and the remainder, i.e.,(u - rootn)
.- Throws:
ArithmeticException
- if n is even and this is negative.
-
sqrtAssign
Set thisMPZ
to the truncated integer part of the square root ofop
.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- if op is negative.
-
sqrtAssign
Set thisMPZ
to the truncated integer part of its square root.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- if this is negative.
-
sqrt
Return anMPZ
whose value is the truncated integer part of the square root ofthis
.- Throws:
ArithmeticException
- if this is negative.
-
sqrtremAssign
Set thisMPZ
to the truncated integer part of the square root ofop
andrem
to the remainder, i.e.,(op - root2)
.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- if op is negative.
-
sqrtremAssign
Set thisMPZ
to the truncated integer part of its square root andrem
to the remainder, i.e.,(this - root2)
.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- if this is negative.
-
sqrtrem
Return twoMPZ
s whose values are the truncated integer part of the square root ofthis
and the remainder, i.e.,(op - root2)
.- Throws:
ArithmeticException
- if this is negative.
-
isPerfectPower
public boolean isPerfectPower()Returntrue
if and only if this number is a perfect power, i.e., if there exist integersa
andb
, with(b > 1)
, such thatthis
equals(ab)
. Under this definition both0
and1
are considered to be perfect powers. Negative values are accepted, but of course can only be odd perfect powers. -
isPerfectSquare
public boolean isPerfectSquare()Returntrue
if and only if this number is a perfect square. Under this definition both0
and1
are considered to be perfect squares. -
isProbabPrime
- Parameters:
reps
- can be used to tune the probability of a non-prime being identified as “probably prime”. Reasonable values of reps are between 15 and 50.- Returns:
- an instance of the
MPZ.PrimalityStatus
enum, telling whetherthis
is definitely prime, probably prime or definitely non-prime.
-
nextprimeAssign
Set thisMPZ
to the next prime greater thenop
. This function uses a probabilistic algorithm to identify primes. For practical purposes it’s adequate, the chance of a composite passing will be extremely small. -
nextprimeAssign
Set thisMPZ
to the next prime greater then itself. This function uses a probabilistic algorithm to identify primes. For practical purposes it’s adequate, the chance of a composite passing will be extremely small. -
nextprime
Return anMPZ
whose value is the next prime greater thenthis
.- See Also:
-
gcdAssign
Set thisMPZ
to the greatest commond divisor ofop1
andop2
. The result is always positive even if one or both input operands are negative. Except if both inputs are zero; then this function definesgcd(0,0) = 0
. -
gcdAssign
Set thisMPZ
to the greatest commond divisor ofthis
andop
. The result is always positive even if one or both operands are negative. Except if boththis
andop
are zero; then this function Return zero. -
gcd
Return anMPZ
whose value is the greatest commond divisor ofthis
andop
.- See Also:
-
gcdUiAssign
Set thisMPZ
to the greatest commond divisor ofop1
andop2
, and return it. If the result does not fit into an unsigned long, then 0 si returned.- See Also:
-
gcdUiAssign
public long gcdUiAssign(long op) Set thisMPZ
to the greatest commond divisor ofop1
andop2
, and returns it. If the result does not fit into an unsigned long, then 0 si returned.- See Also:
-
gcdUi
public long gcdUi(long op) Return the greatest commond divisor ofthis
andop
. If the result does not fit into an unsigned long, 0 is returned. -
gcdextAssign
Set thisMPZ
to the greatest common divisor ofa
andb
, and in addition Sets
andt
to coefficients satisfying(a*s + b*t = gcd)
. Ifs
ort
is null, that value is not computed. See the GMP functionmpz_gcdext
. -
gcdextAssign
Set thisMPZ
to the greatest common divisor ofthis
andop
, and in addition Sets
andt
to coefficients satisfying(this*s + op*t = gcd)
. Ifs
ort
is null, that value is not computed. See the GMP functionmpz_gcdext
. -
gcdext
Return the greatest common divisor ofthis
andop
, together with numberss
andt
satisfying(a*this + b*op = g)
See the GMP functionmpz_gcdext
. -
lcmAssign
Set thisMPZ
to the least common multiple ofop1
andop2
. The result is always non-negative even if one or both input operands are negative. The result will be zero if eitherop1
orop2
is zero. -
lcmAssign
Set thisMPZ
to the least common multiple ofthis
andop
. The result is always non-negative even if one or both input operands are negative. The result will be zero if eitherthis
orop
is zero. -
lcm
Return anMPZ
whose value is the least common multiple ofthis
andop
.- See Also:
-
lcmUiAssign
Set thisMPZ
to the least common multiple ofop1
andop2
.- See Also:
-
lcmUiAssign
Set thisMPZ
to the least common multiple ofthis
andop
.- See Also:
-
lcmUi
Return the least common multiple ofthis
andop
.- See Also:
-
invertAssign
Set thisMPZ
to the inverse ofop1
moduloop2
. If the inverse does not exist, the new value of thisMPZ
is undefined.- Returns:
- true if the inverse exists, false otherwise.
-
invertAssign
Set thisMPZ
to the inverse ofthis
moduloop
. If the inverse does not exist, the new value of thisMPZ
is undefined.- Returns:
- true if the inverse exists, false otherwise.
-
invert
Optionally return, when it exists, anMPZ
whose value is the inverse ofthis
moduloop
. -
jacobi
Return the Jacobi symbol(this / b)
. This is defined only forb
odd. -
legendre
Return the Legendre symbol(this / p)
. This is defined only forp
an odd positive prime, and for suchp
it’s identical to the Jacobi symbol. -
kronecker
Return the Jacobi symbol(this / n)
with the Kronecker extension(this/2)=(2/this)
whenthis
is odd, or(this/2)=0
whenthis
is even. Whenb
is odd the Jacobi symbol and Kronecker symbol are identical. See the GMP functionmpz_kronecker
. -
kronecker
public int kronecker(long b) Return the Jacobi symbol(this / b)
with the Kronecker extension.- See Also:
-
kroneckerUi
public int kroneckerUi(long b) Return the Jacobi symbol(this / b)
with the Kronecker extension.- See Also:
-
kroneckerReverse
public int kroneckerReverse(long a) Return the Jacobi symbol(a / this)
with the Kronecker extension.- See Also:
-
uiKronecker
public int uiKronecker(long a) Return the Jacobi symbol(a / this)
with the Kronecker extension.- See Also:
-
removeAssign
Remove all occurrences of the factorf
fromop
and stores the result in thisMPZ
. The return value is the number of occurrences off
which were removed. -
removeAssign
Remove all occurrences of the factorf
fromthis
MPZ. The return value is the number of occurrences off
which were removed. -
remove
Return the result of removing the factorf
fromthis
, together with the number of occurrences which were removed. -
facUiAssign
Set thisMPZ
to the factorial ofn
. -
facUi
Return anMPZ
whose value is the factorial ofn
. -
dfacUiAssign
Set thisMPZ
to the double factorial ofn
. -
dfacUi
Return anMPZ
whose value the double factorial ofn
. -
mfacUiUiAssign
Set thisMPZ
to them
-multi factorial ofn
. -
mfacUiUi
Return anMPZ
whose value is them
-multi factorial ofn
. -
primorialUiAssign
Set thisMPZ
to the primorial ofn
, i.e., the product of all positive prime numbers<= n
. -
primorialUi
Return anMPZ
whose value is the primorial ofn
, i.e., the product of all positive prime numbers<= n
. -
binUiAssign
Set thisMPZ
to the binomial coefficientn
overk
. Negative values ofn
are supported using the identity(bin(-n,k) = (-1)^k * bin(n+k-1,k))
, see Knuth volume 1 section 1.2.6 part G. -
binUiAssign
Set thisMPZ
to the binomial coefficientthis
overk
. Negative values ofthis
are supported using the identity(bin(-n,k) = (-1)^k * bin(n+k-1,k))
, see Knuth volume 1 section 1.2.6 part G. -
binUi
Return anMPZ
whose value is the binomial coefficientthis
overk
. Negative values ofthis
are supported as inbinUiAssign(it.unich.jgmp.MPZ,long)
. -
binUiUiAssign
Set thisMPZ
to the binomial coefficientn
overk
. -
binUiUi
Return anMPZ
whose value is the binomial coefficientn
overk
. -
fibUiAssign
Set thisMPZ
to then
-th Fibonacci number. -
fibUi
Return anMPZ
whose value is then
-th Fibonacci number. -
fib2UiAssign
Set the value ofthis
andfnsub1
to then
-th and(n-1)
-th Fibonacci numbers respecively. -
fib2Ui
Return twoMPZ
whose values are then
-th and(n-1)
-th Fibonacci numbers. -
lucnumUiAssign
Set thisMPZ
to then
-th Lucas number. -
lucnumUi
Return anMPZ
whose value is then
-th Lucas number. -
lucnum2UiAssign
Set the value ofthis
andfnsub1
to then
-th and(n-1)
-th Lucas numbers respecively. -
lucnum2Ui
Return twoMPZ
whose values are then
-th and(n-1)
-th Lucas numbers. -
cmp
Comparethis
withop
. Return a positive value if(this > op)
, zero ifthis = op
, or a negative value ifthis < op
. -
cmp
public int cmp(double op) Comparethis
withop
. Return a positive value if(this > op)
, zero ifthis = op
, or a negative value ifthis < op
. The value ofop
may be infinite, but the result is undefined on NaNs.- Throws:
ArithmeticException
- ifop
is a NaN.
-
cmp
public int cmp(long op) Comparethis
withop
. Return a positive value if(this > op)
, zero ifthis = op
, or a negative value ifthis < op
. -
cmpUi
public int cmpUi(long op) Comparethis
withop
. Return a positive value if(this > op)
, zero ifthis = op
, or a negative value ifthis < op
. -
cmpabs
Compare the absolute values ofthis
andop
. Return a positive value if(abs(this) > abs(op))
, zero ifabs(this) = abs(op)
, or a negative value ifabs(this) < abs(op)
. -
cmpabs
public int cmpabs(double op) Compare the absolute values ofthis
andop
. Return a positive value if(abs(this) > abs(op))
, zero ifabs(this) = abs(op)
, or a negative value ifabs(this) < abs(op)
. The value ofop
may be infinite, but the result is undefined on NaNs.- Throws:
ArithmeticException
- ifop
is a NaN.
-
cmpabsUi
public int cmpabsUi(long op) Compare the absolute values ofthis
andop
. Return a positive value if(abs(this) > abs(op))
, zero ifabs(this) = abs(op)
, or a negative value ifabs(this) < abs(op)
. -
sgn
public int sgn()Return+1
if(this > 0)
,0
if(this = 0)
and-1
ifthis < 0
. -
andAssign
Set thisMPZ
to(op1 & op2)
. -
andAssign
Set thisMPZ
to(this & op)
. -
and
Return anMPZ
whose value is(this & op)
. -
iorAssign
Set thisMPZ
to(op1 | op2)
. -
iorAssign
Set thisMPZ
to(this | op)
. -
ior
Return anMPZ
whose value is(this | op)
. -
xorAssign
Set thisMPZ
to(op1 ^ op2)
. -
xorAssign
Set thisMPZ
to(this ^ op)
. -
xor
Return anMPZ
whose value is(this ^ op)
. -
comAssign
Set thisMPZ
to(~ op)
. -
comAssign
Set thisMPZ
to(~ this)
. -
com
Return anMPZ
whose value is(~ op)
. -
popcount
public long popcount()If thisMPZ
is non-negative, return its population count, which is the number of1
bits in its binary representation. If thisMPZ
is negative, the number of1
s is infinite, and the return value is the largest possible value for the native typemp_bitcnt_t
. -
hamdist
Ifthis
andop
are both>= 0
or both< 0
, return the Hamming distance between them, which is the number of bit positions wherethis
andop
have different bit values. If one operand is>= 0
and the other< 0
then the number of bits different is infinite, and the return value is the largest possible value for the native typemp_bitcnt_t
. -
scan0
public long scan0(long starting_bit) Scan thisMPZ
, starting from bitstarting_bit
, towards more significant bits, until the first0
bit is found. Return the index of the found bit. -
scan1
public long scan1(long starting_bit) Scanthis
, starting from bitstarting_bit
, towards more significant bits, until the first1
bit is found. Return the index of the found bit. -
setbitAssign
Set the bitindex
of thisMPZ
. -
setbit
Return anMPZ
whose value is(this | 2index)
. -
clrbitAssign
Clear the bitindex
of thisMPZ
. -
clrbit
Return anMPZ
whose value is(this & ~ 2index)
. -
combitAssign
Complement the bitindex
of thisMPZ
. -
combit
Return anMPZ
whose value is(this ^ 2index)
. -
tstbit
public int tstbit(long index) Return the bitindex
of thisMPZ
. -
urandombAssign
Set thisMPZ
to a uniformly distributed random integer in the range0
to(2n - 1)
, inclusive. -
urandomb
Return anMPZ
whose value is an uniformly distributed random integer in the range0
} to(2n - 1)
, inclusive. -
urandommAssign
Set thisMPZ
to a uniformly distributed random integer in the range0
to(n - 1)
, inclusive. -
urandomm
Return anMPZ
whose value is an uniformly distributed random integer in the range0
to(n - 1)
, inclusive. -
rrandombAssign
Set thisMPZ
to a random integer with long strings of zeros and ones in the binary representation. Useful for testing functions and algorithms, since this kind of random numbers have proven to be more likely to trigger corner-case bugs. The random number will be in the range(2n - 1)
to(2n - 1)
, inclusive. -
rrandomb
Return anMPZ
whose value is a random integer with long strings of zeros and ones in the binary representation. Useful for testing functions and algorithms, since this kind of random numbers have proven to be more likely to trigger corner-case bugs. The random number will be in the range(2n - 1)
to(2n - 1)
, inclusive. -
randomAssign
Deprecated.useurandombAssign(it.unich.jgmp.RandState,long)
orurandommAssign(it.unich.jgmp.RandState,it.unich.jgmp.MPZ)
instead, since this method uses a global random state and it is not reentrant.Set thisMPZ
to a random integer of at mostmax_size
limbs. The generated random number doesn’t satisfy any particular requirements of randomness. Negative random numbers are generated whenmax_size
is negative.- Returns:
- this
MPZ
.
-
random
Deprecated.useurandomb(it.unich.jgmp.RandState,long)
orurandomm(it.unich.jgmp.RandState,it.unich.jgmp.MPZ)
instead, since this method uses a global random state and it is not reentrant.Return anMPZ
whose value is a random integer of at mostmax_size
limbs. The generated random number doesn’t satisfy any particular requirements of randomness. Negative random numbers are generated whenmax_size
is negative. -
random2Assign
Deprecated.userrandombAssign(it.unich.jgmp.RandState,long)
instead, since this method uses a global random state and it is not reentrant.Set thisMPZ
to a random integer of at mostmax_size
limbs, with long strings of zeros and ones in the binary representation. Useful for testing functions and algorithms, since this kind of random numbers have proven to be more likely to trigger corner-case bugs. Negative random numbers are generated whenmax_size
is negative.- Returns:
- this
MPZ
.
-
random2
Deprecated.userrandomb(it.unich.jgmp.RandState,long)
instead, since this method uses a global random state and it is not reentrant.Return anMPZ
whose value is a random integer of at mostmax_size
limbs, with long strings of zeros and ones in the binary representation. Useful for testing functions and algorithms, since this kind of random numbers have proven to be more likely to trigger corner-case bugs. Negative random numbers are generated whenmax_size
is negative. -
bufferImportAssign
Set thisMPZ
from the buffer of word data atop
. See the detailed description in the documentation of the GMP functionmpz_import
. The parametercount
in the prototype ofmpz_import
is automatically computed by the capacity of the bufferop
. Thesize
parameter is declared asint
instead oflong
since Java does not allow byte buffers to be longer than 4GB. -
bufferImport
Return anMPZ
whose value is determined from the buffer of word data atop
. Thesize
parameter is declared asint
instead oflong
since Java does not allow byte buffers to be longer than 4GB.- See Also:
-
bufferExport
Return aByteBuffer
filled with word data from thisMPZ
. See the detailed description in the documentation of the GMP functionmpz_export
. We let the function allocate the buffer, since it the easier and safer. The outputcount
of the original GMP function is not needed, since it corresponds to the capacity of the resultingByteBuffer
. Thesize
parameter is declared asint
instead oflong
since Java does not allow byte buffers to be longer than 4GB. -
fitsUlong
public boolean fitsUlong()Returntrue
if and only if thisMPZ
fits into a native unsigned long. -
fitsSlong
public boolean fitsSlong()Returntrue
if and only if thisMPZ
fits into a native signed long. -
fitsUint
public boolean fitsUint()Returntrue
if and only if thisMPZ
fits into a native unsigned int. -
fitsSint
public boolean fitsSint()Returntrue
if and only if thisMPZ
fits into a native signed int. -
fitsUshort
public boolean fitsUshort()Returntrue
if and only if thisMPZ
fits into a native unsigned short. -
fitsSshort
public boolean fitsSshort()Returntrue
if and only if thisMPZ
fits into a native signed short. -
isOdd
public boolean isOdd()Returntrue
if and only if thisMPZ
is odd. -
isEven
public boolean isEven()Returntrue
if and only if thisMPZ
is even -
isZero
public boolean isZero()Returntrue
if and only if thisMPZ
is zero. -
sizeinbase
public long sizeinbase(int base) Return the size of thisMPZ
measured in number of digits in the specifiedbase
. See the the GMP functionmpz_sizeinbase
.- Throws:
IllegalArgumentException
- if base is not between 2 and 62.
-
setValue
Set thisMPZ
toop
.- Returns:
- this
MPZ
.
-
setValue
Set thisMPZ
to signed longop
.- Returns:
- this
MPZ
.
-
setValue
Set thisMPZ
to the truncation opop
.- Returns:
- this
MPZ
. - Throws:
ArithmeticException
- ifop
is not a finite number. In this case,this
is not altered.
-
setValue
Set thisMPZ
to the truncation opop
.- Returns:
- this
MPZ
.
-
setValue
Set thisMPZ
to the truncation opop
.- Returns:
- this
MPZ
.
-
setValue
Set thisMPZ
to the number represented by the stringstr
in the specifiedbase
. See the GMP functionmpz_set_str
.- Throws:
NumberFormatException
- if eitherbase
is not valid orstr
is not a valid number representation in the specified base. In this case,this
is not altered.
-
setValue
Set thisMPZ
to the value represented by the stringstr
in decimal base.- Throws:
NumberFormatException
- ifstr
is not a valid number representation in decimal base.- See Also:
-
setValue
Sets thisMPZ
toop
.- Returns:
- this
MPZ
.
-
compareTo
Compare thisMPZ
withop
. Return a positive value if(this > op)
, zero ifthis = op
, or a negative value ifthis < op
. This order is compatible with equality.- Specified by:
compareTo
in interfaceComparable<MPZ>
-
equals
Compare thisMPZ
with the objectop
for equality. It returnstrue
if and only ifop
is anMPZ
with the same value ofthis
. -
hashCode
public int hashCode()Return a hash code value for thisMPZ
. -
longValue
public long longValue()Convert thisMPZ
to a signed long. If this number is too big to fit a native signed long, return the least significant part, preserving the sign. -
intValue
public int intValue()Convert thisMPZ
to a signed int, truncating if necessary. -
doubleValue
public double doubleValue()Convert thisMPZ
to a double, truncating if necessary. If the exponent from the conversion is too big, the result is system dependent. An infinity is returned where available. A hardware overflow trap may or may not occur.- Specified by:
doubleValue
in classNumber
-
floatValue
public float floatValue()Convert thisMPZ
to a float, truncating if necessary.- Specified by:
floatValue
in classNumber
-
toString
Convert thisMPZ
to its string representation in the specifiedbase
, ornull
if the base is not valid. See the GMP functionmpz_get_str
. -
toString
Convert thisMPZ
to its decimal string representation. -
writeObject
- Throws:
IOException
-
readObject
- Throws:
IOException
ClassNotFoundException
-
readObjectNoData
- Throws:
ObjectStreamException
-
urandomb(it.unich.jgmp.RandState,long)
orurandomm(it.unich.jgmp.RandState,it.unich.jgmp.MPZ)
instead, since this method uses a global random state and it is not reentrant.