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
MPZclass.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classCleaning action for theMPZclass.static enumResult enumeration for themethod.invalid reference
isProbabPrime -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate MpzTThe pointer to the nativempz_tobject.private static final longVersion for serializability. -
Constructor Summary
ConstructorsModifierConstructorDescriptionMPZ()Build anMPZwhose value is zero.MPZ(double op) Build anMPZwhose value is the truncation ofop.MPZ(long op) Build anMPZwhose value isop.Build anMPZwhose value is the truncation ofop.Build anMPZwhose value is the truncation ofop.Build anMPZwhose value isop.privateA private constructor which build anMPZstarting from a pointer to its native data object.Build anMPZwhose value is the number represented by the stringstrin decimal base.Build anMPZwhose value is the number represented by the stringstrin the specifiedbase.MPZ(BigInteger op) Builds anMPZwhose value is the same asop. -
Method Summary
Modifier and TypeMethodDescriptionabs()Return anMPZwhose value is the absolute value ofthis.Set thisMPZto its absolute value.Set thisMPZto the absolute value ofop.Return anMPZwhose value is(this + op).Set thisMPZto(this + op)Set thisMPZto(op1 + op2).Return anMPZwhose value is(this + op1 * op2).addmulAssign(MPZ op1, MPZ op2) Add(op1 * op2)to thisMPZ.Return anMPZwhose value is(this + op1 * op2).addmulUiAssign(MPZ op1, long op2) Add(op1 * op2)to thisMPZ.addUi(long op) Return anMPZwhose value is(this + op).addUiAssign(long op) Set thisMPZto(this + op)addUiAssign(MPZ op1, long op2) Set thisMPZto(op1 + op2).Return anMPZwhose value is(this & op).Set thisMPZto(this & op).Set thisMPZto(op1 & op2).binUi(long k) Return anMPZwhose value is the binomial coefficientthisoverk.binUiAssign(long k) Set thisMPZto the binomial coefficientthisoverk.binUiAssign(MPZ n, long k) Set thisMPZto the binomial coefficientnoverk.static MPZbinUiUi(long n, long k) Return anMPZwhose value is the binomial coefficientnoverk.binUiUiAssign(long n, long k) Set thisMPZto the binomial coefficientnoverk.bufferExport(int order, int size, int endian, long nails) Return aByteBufferfilled with word data from thisMPZ.static MPZbufferImport(int order, int size, int endian, long nails, ByteBuffer op) Return anMPZwhose value is determined from the buffer of word data atop.bufferImportAssign(int order, int size, int endian, long nails, ByteBuffer op) Set thisMPZfrom the buffer of word data atop.Return anMPZwhose value is the quotient of the integer division(this / d), rounded towards +∞.cdivq2Exp(long b) Return anMPZwhose value is the quotient of the integer division(this / 2b), rounded towards +∞.cdivq2ExpAssign(long b) Set thisMPZto the quotient of the integer division(this / 2b), rounded toward +∞.cdivq2ExpAssign(MPZ n, long b) Set thisMPZto the quotient of the integer division(n / 2b), rounded toward +∞.cdivqAssign(MPZ d) Set thisMPZto the quotient of the integer division(this / d), rounded towards +∞.cdivqAssign(MPZ n, MPZ d) Set thisMPZto the quotient of the integer division(n / d), rounded towards +∞.Return a pair ofMPZs whose values are the quotient and remainder of the integer division(this / d), rounded towards +∞.cdivqrAssign(MPZ r, MPZ d) Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards +∞.cdivqrAssign(MPZ r, MPZ n, MPZ d) Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards +∞.longcdivqrUiAssign(MPZ r, long d) Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards +∞; it also returns the remainder.longcdivqrUiAssign(MPZ r, MPZ n, long d) Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards +∞; it also returns the remainder.longcdivqUiAssign(long d) Set thisMPZto the quotient of the integer division(this / d), rounded towards +∞; it also returns the remainder.longcdivqUiAssign(MPZ n, long d) Set thisMPZto the quotient of the integer division(n / d), rounded towards +∞; it also Return the remainder.Return anMPZwhose value is the remainder of the integer division(this / d), rounded towards +∞.cdivr2Exp(long b) Return anMPZwhose value is the remainder of the integer division(this / 2b), rounded towards +∞.cdivr2ExpAssign(long b) Set thisMPZto the remainder of the integer division(this / 2b), rounded toward +∞.cdivr2ExpAssign(MPZ n, long b) Set thisMPZto the remainder of the integer division(n / 2b), rounded toward +∞.cdivrAssign(MPZ d) Set thisMPZto the remainder of the integer division(this / d), rounded towards +∞.cdivrAssign(MPZ n, MPZ d) Set thisMPZto the remainder of the integer division(n / d), rounded towards +∞.longcdivrUiAssign(long d) Set thisMPZto the remainder of the integer division(this / d), rounded towards +∞; it also returns the remainder.longcdivrUiAssign(MPZ n, long d) Set thisMPZto the remainder of the integer division(n / d), rounded towards +∞; it also returns the remainder.longcdivUi(long d) Return the remainder of the integer division(this / d), rounded towards +∞.clrbit(long index) Return anMPZwhose value is(this & ~ 2index).clrbitAssign(long index) Clear the bitindexof thisMPZ.intcmp(double op) Comparethiswithop.intcmp(long op) Comparethiswithop.intComparethiswithop.intcmpabs(double op) Compare the absolute values ofthisandop.intCompare the absolute values ofthisandop.intcmpabsUi(long op) Compare the absolute values ofthisandop.intcmpUi(long op) Comparethiswithop.com()Return anMPZwhose value is(~ op).Set thisMPZto(~ this).Set thisMPZto(~ op).combit(long index) Return anMPZwhose value is(this ^ 2index).combitAssign(long index) Complement the bitindexof thisMPZ.intCompare thisMPZwithop.static MPZdfacUi(long n) Return anMPZwhose value the double factorial ofn.dfacUiAssign(long n) Set thisMPZto the double factorial ofn.Return anMPZwhose value is the quotient of(this / d).Set thisMPZto the quotient of(this / d).divexactAssign(MPZ n, MPZ d) Set thisMPZto the quotient of(n / d).divexactUi(long d) Return anMPZwhose value is the quotient of(this / d).divexactUiAssign(long d) Set thisMPZto the quotient of(this / d).divexactUiAssign(MPZ n, long d) Set thisMPZto the quotient of(n / d).doubleConvert thisMPZto a double, truncating if necessary.booleanCompare thisMPZwith the objectopfor equality.static MPZfacUi(long n) Return anMPZwhose value is the factorial ofn.facUiAssign(long n) Set thisMPZto the factorial ofn.Return anMPZwhose value is the quotient of the integer division(this / d), rounded towards -∞.fdivq2Exp(long b) Return anMPZwhose value is the quotient of the integer division(this / 2b), rounded towards -∞.fdivq2ExpAssign(long b) Set thisMPZto the quotient of the integer division(this / 2b), rounded toward -∞.fdivq2ExpAssign(MPZ n, long b) Set thisMPZto the quotient of the integer division(n / 2b), rounded toward -∞.fdivqAssign(MPZ d) Set thisMPZto the quotient of the integer division(this / d), rounded towards -∞.fdivqAssign(MPZ n, MPZ d) Set thisMPZto the quotient of the integer division(n / d), rounded towards -∞.Return twoMPZs whose values are the quotient and remainder of the integer division(this / d), rounded towards -∞.fdivqrAssign(MPZ r, MPZ d) Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards -∞.fdivqrAssign(MPZ r, MPZ n, MPZ d) Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards -∞.longfdivqrUiAssign(MPZ r, long d) Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards -∞; it also returns the absolute value of the remainder.longfdivqrUiAssign(MPZ r, MPZ n, long d) Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards -∞; it also returns the absolute value of the remainder.longfdivqUiAssign(long d) Set thisMPZto the quotient of the integer division(this / d), rounded towards -∞; it also returns the absolute value of the remainder.longfdivqUiAssign(MPZ n, long d) Set thisMPZto the quotient of the integer division(n / d), rounded towards -∞; it also returns the absolute value of the remainder.Return anMPZwhose value is the remainder of the integer division(this / d), rounded towards -∞.fdivr2Exp(long b) Return anMPZwhose value is the remainder of the integer division(this / 2b), rounded towards -∞.fdivr2ExpAssign(long b) Set thisMPZto the remainder of the integer division(this / 2b), rounded toward -∞.fdivr2ExpAssign(MPZ n, long b) Set thisMPZto the remainder of the integer division(n / 2b), rounded toward -∞.fdivrAssign(MPZ d) Set thisMPZto the remainder of the integer division(this / d), rounded towards -∞.fdivrAssign(MPZ n, MPZ d) Set thisMPZto the remainder of the integer division(n / d), rounded towards -∞.longfdivrUiAssign(long d) Set thisMPZto the remainder of the integer division(this / d), rounded towards -∞; it also returns the absolute value of the remainder.longfdivrUiAssign(MPZ n, long d) Set thisMPZto the remainder of the integer division(n / d), rounded towards -∞; it also returns the absolute value of the remainder.longfdivUi(long d) Return the remainder of the integer division(this / d), rounded towards -∞.fib2Ui(long n) Return twoMPZwhose values are then-th and(n-1)-th Fibonacci numbers.fib2UiAssign(MPZ fnsub1, long n) Set the value ofthisandfnsub1to then-th and(n-1)-th Fibonacci numbers respecively.static MPZfibUi(long n) Return anMPZwhose value is then-th Fibonacci number.fibUiAssign(long n) Set thisMPZto then-th Fibonacci number.booleanfitsSint()Returntrueif and only if thisMPZfits into a native signed int.booleanReturntrueif and only if thisMPZfits into a native signed long.booleanReturntrueif and only if thisMPZfits into a native signed short.booleanfitsUint()Returntrueif and only if thisMPZfits into a native unsigned int.booleanReturntrueif and only if thisMPZfits into a native unsigned long.booleanReturntrueif and only if thisMPZfits into a native unsigned short.floatConvert thisMPZto a float, truncating if necessary.Return anMPZwhose value is the greatest commond divisor ofthisandop.Set thisMPZto the greatest commond divisor ofthisandop.Set thisMPZto the greatest commond divisor ofop1andop2.Return the greatest common divisor ofthisandop, together with numberssandtsatisfying(a*this + b*op = g)See the GMP functionmpz_gcdext.gcdextAssign(MPZ s, MPZ t, MPZ op) Set thisMPZto the greatest common divisor ofthisandop, and in addition Setsandtto coefficients satisfying(this*s + op*t = gcd).gcdextAssign(MPZ s, MPZ t, MPZ a, MPZ b) Set thisMPZto the greatest common divisor ofaandb, and in addition Setsandtto coefficients satisfying(a*s + b*t = gcd).longgcdUi(long op) Return the greatest commond divisor ofthisandop.longgcdUiAssign(long op) Set thisMPZto the greatest commond divisor ofop1andop2, and returns it.longgcdUiAssign(MPZ op1, long op2) Set thisMPZto the greatest commond divisor ofop1andop2, and return it.Converts thisMPZto BigInteger.doublegetD()Convert thisMPZto a double, truncating if necessary.getD2Exp()Convert thisMPZto a pair made of mantissa and exponent, truncating if necessary.Return the native pointer to the GMP object.longgetSi()Convert thisMPZto a signed long.getStr(int base) Return the String representation of thisMPZin the specifiedbase, ornullif the base is not valid.longgetUi()Convert thisMPZto an unsigned long.longIfthisandopare both>= 0or both< 0, return the Hamming distance between them, which is the number of bit positions wherethisandophave different bit values.inthashCode()Return a hash code value for thisMPZ.static MPZinit()Return anMPZwhose value is zero.static MPZinit2(long n) Return anMPZwhose value is zero, with pre-allocated space forn-bit numbers.static MPZinitSet(double op) Return anMPZwhose value is the truncation ofop.static MPZinitSet(long op) Return anMPZwhose value isop.static MPZReturn anMPZwhose value isop.Return anMPZwhose value is the number represented by the stringstrin the specifiedbase.static MPZinitSetUi(long op) Return anMPZwhose value isop.intintValue()Convert thisMPZto a signed int, truncating if necessary.Optionally return, when it exists, anMPZwhose value is the inverse ofthismoduloop.booleaninvertAssign(MPZ op) Set thisMPZto the inverse ofthismoduloop.booleaninvertAssign(MPZ op1, MPZ op2) Set thisMPZto the inverse ofop1moduloop2.Return anMPZwhose value is(this | op).Set thisMPZto(this | op).Set thisMPZto(op1 | op2).booleanisCongruent(MPZ c, MPZ d) Returntrueif and only ifthisis congruent tocmodulod.booleanisCongruent2Exp(MPZ c, long b) Returntrueif and only ifthisis congruent tocmodulo2b.booleanisCongruentUi(long c, long d) Returntrueif and only ifthisis congruent tocmodulod.booleanisDivisible(MPZ d) Returntrueif and only ifthisis exactly divisible byd.booleanisDivisible2Exp(long b) Returntrueif and only ifthisis exactly divisible by2b.booleanisDivisibleUi(long d) Returntrueif and only ifthisis exactly divisible byd.booleanisEven()Returntrueif and only if thisMPZis evenbooleanisOdd()Returntrueif and only if thisMPZis odd.booleanReturntrueif and only if this number is a perfect power, i.e., if there exist integersaandb, with(b > 1), such thatthisequals(ab).booleanReturntrueif and only if this number is a perfect square.isProbabPrime(int reps) Returntrueif and only ifthisis prime.booleanisZero()Returntrueif and only if thisMPZis zero.intReturn the Jacobi symbol(this / b).intkronecker(long b) Return the Jacobi symbol(this / b)with the Kronecker extension.intReturn the Jacobi symbol(this / n)with the Kronecker extension(this/2)=(2/this)whenthisis odd, or(this/2)=0whenthisis even.intkroneckerReverse(long a) Return the Jacobi symbol(a / this)with the Kronecker extension.intkroneckerUi(long b) Return the Jacobi symbol(this / b)with the Kronecker extension.Return anMPZwhose value is the least common multiple ofthisandop.Set thisMPZto the least common multiple ofthisandop.Set thisMPZto the least common multiple ofop1andop2.lcmUi(long op) Return the least common multiple ofthisandop.lcmUiAssign(long op) Set thisMPZto the least common multiple ofthisandop.lcmUiAssign(MPZ op1, long op2) Set thisMPZto the least common multiple ofop1andop2.intReturn the Legendre symbol(this / p).longConvert thisMPZto a signed long.lucnum2Ui(long n) Return twoMPZwhose values are then-th and(n-1)-th Lucas numbers.lucnum2UiAssign(MPZ fnsub1, long n) Set the value ofthisandfnsub1to then-th and(n-1)-th Lucas numbers respecively.static MPZlucnumUi(long n) Return anMPZwhose value is then-th Lucas number.lucnumUiAssign(long n) Set thisMPZto then-th Lucas number.static MPZmfacUiUi(long n, long m) Return anMPZwhose value is them-multi factorial ofn.mfacUiUiAssign(long n, long m) Set thisMPZto them-multi factorial ofn.Return anMPZwhose value is(this mod d).Set thisMPZto(this mod d).Set thisMPZto(n mod d).longmodUi(long d) Return anMPZwhose value is(this mod d).longmodUiAssign(long d) Set thisMPZto(n mod d); it also returns the result.longmodUiAssign(MPZ n, long d) Set thisMPZto(n mod d); it also returns the result.mul(long op) Return anMPZwhose value is(this * op).Return anMPZwhose value is(this * op).mul2Exp(long b) Return anMPZwhose value is(this * 2b).mul2ExpAssign(long b) Set thisMPZto(this * 2b).mul2ExpAssign(MPZ op, long b) Set thisMPZto(op * 2b).mulAssign(long op) Set thisMPZto(this * op)Set thisMPZto(this * op)Set thisMPZto(op1 * op2).Set thisMPZto(op1 * op2).mulUi(long op) Return anMPZwhose value is(this * op).mulUiAssign(long op) Set thisMPZto(this * op)mulUiAssign(MPZ op1, long op2) Set thisMPZto(op1 * op2).neg()Return anMPZwhose value is the quotient of(- this).Set thisMPZto its opposite.Set thisMPZto(- op).Return anMPZwhose value is the next prime greater thenthis.Set thisMPZto the next prime greater then itself.nextprimeAssign(MPZ op) Set thisMPZto the next prime greater thenop.longpopcount()If thisMPZis non-negative, return its population count, which is the number of1bits in its binary representation.Return anMPZwhose value is(thisexp)modulomod.powmAssign(MPZ exp, MPZ mod) Set thisMPZto(thisexp)modulomod.powmAssign(MPZ base, MPZ exp, MPZ mod) Set thisMPZto(baseexp)modulomod.Return anMPZwhose value is(thisexp)modulomod.powmSecAssign(MPZ exp, MPZ mod) Set thisMPZto(thisexp)modulomod.powmSecAssign(MPZ base, MPZ exp, MPZ mod) Set thisMPZto(baseexp)modulomod.Return anMPZwhose value is(thisexp)modulomod.powmUiAssign(long exp, MPZ mod) Set thisMPZto(thisexp)modulomod.powmUiAssign(MPZ base, long exp, MPZ mod) Set thisMPZto(baseexp)modulomod.powUi(long exp) Return anMPZwhose value is(thisexp).static MPZpowUi(long base, long exp) Return anMPZwhose value is(baseexp).powUiAssign(long exp) Set thisMPZto(thisexp).powUiAssign(long base, long exp) Set thisMPZto(baseexp).powUiAssign(MPZ base, long exp) Set thisMPZto(baseexp).static MPZprimorialUi(long n) Return anMPZwhose value is the primorial ofn, i.e., the product of all positive prime numbers<= n.primorialUiAssign(long n) Set thisMPZto the primorial ofn, i.e., the product of all positive prime numbers<= n.static MPZrandom(long max_size) Deprecated.static MPZrandom2(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 voidprivate voidrealloc2(long n) Changes the space allocated for this number tonbits.Return the result of removing the factorffromthis, together with the number of occurrences which were removed.longremoveAssign(MPZ f) Remove all occurrences of the factorffromthisMPZ.longremoveAssign(MPZ op, MPZ f) Remove all occurrences of the factorffromopand stores the result in thisMPZ.root(long n) Return anMPZwhose value is the truncated integer part of thenth root ofthis, and a boolean flag which is true when the result is exact.booleanrootAssign(long n) Set thisMPZto the truncated integer part of itsnth root.booleanrootAssign(MPZ op, long n) Set thisMPZto the truncated integer part of thenth root ofop.rootrem(long n) Return twoMPZs whose values are the truncated integer part of thenth root ofthisand the remainder, i.e.,(u - rootn).rootremAssign(MPZ rem, long n) Set thisMPZto the truncated integer part of the itsnth root andremto the remainder, i.e.,(this - rootn).rootremAssign(MPZ rem, MPZ u, long n) Set thisMPZto the truncated integer part of thenth root ofuandremto the remainder, i.e.,(u - rootn).static MPZReturn anMPZwhose value is a random integer with long strings of zeros and ones in the binary representation.rrandombAssign(RandState s, long n) Set thisMPZto a random integer with long strings of zeros and ones in the binary representation.longscan0(long starting_bit) Scan thisMPZ, starting from bitstarting_bit, towards more significant bits, until the first0bit is found.longscan1(long starting_bit) Scanthis, starting from bitstarting_bit, towards more significant bits, until the first1bit is found.set(double op) Set thisMPZto the truncation ofop.set(long op) Set thisMPZtoop.Set thisMPZto the truncation ofop.Set thisMPZto the truncation ofop.Set thisMPZtoop.(package private) static voidset(MpzT mpzNative, BigInteger op) intSet thisMPZto the number represented by the stringstrin the specifiedbase.set(BigInteger op) Sets thisMPZtoop.setbit(long index) Return anMPZwhose value is(this | 2index).setbitAssign(long index) Set the bitindexof thisMPZ.setUi(long op) Set thisMPZtoop.setValue(double op) Set thisMPZto the truncation opop.setValue(long op) Set thisMPZto signed longop.Set thisMPZto the truncation opop.Set thisMPZto the truncation opop.Set thisMPZtoop.Set thisMPZto the value represented by the stringstrin decimal base.Set thisMPZto the number represented by the stringstrin the specifiedbase.setValue(BigInteger op) Sets thisMPZtoop.intsgn()Return+1if(this > 0),0if(this = 0)and-1ifthis < 0.longsizeinbase(int base) Return the size of thisMPZmeasured in number of digits in the specifiedbase.sqrt()Return anMPZwhose value is the truncated integer part of the square root ofthis.Set thisMPZto the truncated integer part of its square root.sqrtAssign(MPZ op) Set thisMPZto the truncated integer part of the square root ofop.sqrtrem()Return twoMPZs whose values are the truncated integer part of the square root ofthisand the remainder, i.e.,(op - root2).sqrtremAssign(MPZ rem) Set thisMPZto the truncated integer part of its square root andremto the remainder, i.e.,(this - root2).sqrtremAssign(MPZ rem, MPZ op) Set thisMPZto the truncated integer part of the square root ofopandremto the remainder, i.e.,(op - root2).Return anMPZwhose value is(this - op).Set thisMPZto(this - op)Set thisMPZto(op1 - op2).Return anMPZwhose value is(this - op1 * op2).submulAssign(MPZ op1, MPZ op2) Subtract(op1 * op2)to thisMPZ.Return anMPZwhose value is(this - op1 * op2).submulUiAssign(MPZ op1, long op2) Subtract(op1 * op2)to thisMPZ.subUi(long op) Return anMPZwhose value is(this - op).subUiAssign(long op) Set thisMPZto(this - op)subUiAssign(MPZ op1, long op2) Set thisMPZto(op1 - op2).Swap the value of thisMPZwith the value ofop.Return anMPZwhose value is the quotient of the integer division(this / d), rounded towards zero.tdivq2Exp(long b) Return anMPZwhose value is the quotient of the integer division(this / 2b), rounded towards zero.tdivq2ExpAssign(long b) Set thisMPZto the quotient of the integer division(this / 2b), rounded toward zero.tdivq2ExpAssign(MPZ n, long b) Set thisMPZto the quotient of the integer division(n / 2b), rounded toward zero.tdivqAssign(MPZ d) Set thisMPZto the quotient of the integer division(this / d), rounded towards zero.tdivqAssign(MPZ n, MPZ d) Set thisMPZto the quotient of the integer division(n / d), rounded towards zero.Return twoMPZs whose values are the quotient and remainder of the integer division(this / d), rounded towards zero.tdivqrAssign(MPZ r, MPZ d) Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards zero.tdivqrAssign(MPZ r, MPZ n, MPZ d) Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards zero.longtdivqrUiAssign(MPZ r, long d) Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards zero; it also returns the absolute value of the remainder.longtdivqrUiAssign(MPZ r, MPZ n, long d) Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards zero; it also returns the absolute value of the remainder.longtdivqUiAssign(long d) Set thisMPZto the quotient of the integer division(this / d), rounded towards zero; it also returns the absolute value of the remainder.longtdivqUiAssign(MPZ n, long d) Set thisMPZto the quotient of the integer division(n / d), rounded towards zero; it also returns the absolute value of the remainder.Return anMPZwhose value is the remainder of the integer division(this / d), rounded towards zero.tdivr2Exp(long b) Return anMPZwhose value is the remainder of the integer division(this / 2b), rounded towards zero.tdivr2ExpAssign(long b) Set thisMPZto the remainder of the integer division(this / 2b), rounded toward zero.tdivr2ExpAssign(MPZ n, long b) Set thisMPZto the remainder of the integer division(n / 2b), rounded toward zero.tdivrAssign(MPZ d) Set thisMPZto the remainder of the integer division(this / d), rounded towards zero.tdivrAssign(MPZ n, MPZ d) Set thisMPZto the remainder of the integer division(n / d), rounded towards zero.longtdivrUiAssign(long d) Set thisMPZto the remainder of the integer division(this / d), rounded towards zero; it also returns the absolute value of the remainder.longtdivrUiAssign(MPZ n, long d) Set thisMPZto the remainder of the integer division(n / d), rounded towards zero; it also returns the absolute value of the remainder.longtdivUi(long d) Return the remainder of the integer division(this / d), rounded towards zero.toString()Convert thisMPZto its decimal string representation.toString(int base) Convert thisMPZto its string representation in the specifiedbase, ornullif the base is not valid.inttstbit(long index) Return the bitindexof thisMPZ.intuiKronecker(long a) Return the Jacobi symbol(a / this)with the Kronecker extension.uiSub(long op) Return anMPZwhose value is(op - this).uiSubAssign(long op) Set thisMPZto(op - this)uiSubAssign(long op1, MPZ op2) Set thisMPZto(op1 - op2).static MPZReturn anMPZwhose value is an uniformly distributed random integer in the range0} to(2n - 1), inclusive.urandombAssign(RandState s, long n) Set thisMPZto a uniformly distributed random integer in the range0to(2n - 1), inclusive.static MPZReturn anMPZwhose value is an uniformly distributed random integer in the range0to(n - 1), inclusive.urandommAssign(RandState s, MPZ n) Set thisMPZto a uniformly distributed random integer in the range0to(n - 1), inclusive.private voidReturn anMPZwhose value is(this ^ op).Set thisMPZto(this ^ op).Set thisMPZto(op1 ^ op2).Methods inherited from class Number
byteValue, shortValue
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDVersion for serializability.- See Also:
-
mpzNative
The pointer to the nativempz_tobject.
-
-
Constructor Details
-
MPZ
A private constructor which build anMPZstarting from a pointer to its native data object. The native object needs to be already initialized. -
MPZ
public MPZ()Build anMPZwhose value is zero. -
MPZ
Build anMPZwhose value isop. -
MPZ
public MPZ(long op) Build anMPZwhose value isop. -
MPZ
public MPZ(double op) Build anMPZwhose value is the truncation ofop.- Throws:
ArithmeticException- ifopis not a finite number.
-
MPZ
Build anMPZwhose value is the truncation ofop. -
MPZ
Build anMPZwhose value is the truncation ofop. -
MPZ
Build anMPZwhose value is the number represented by the stringstrin the specifiedbase. See the GMP functionmpz_init_set_str.- Throws:
NumberFormatException- if eitherbaseis not valid orstris not a valid string in the specifiedbase.
-
MPZ
Build anMPZwhose value is the number represented by the stringstrin decimal base. See the GMP functionmpz_init_set_str.- Throws:
NumberFormatException- ifstris not a valid number representation in decimal base.
-
MPZ
Builds anMPZwhose value is the same asop.
-
-
Method Details
-
getNative
Return the native pointer to the GMP object. -
init
Return anMPZwhose value is zero. -
init2
-
realloc2
Changes the space allocated for this number tonbits. 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
-
setUi
-
set
Set thisMPZto the truncation ofop.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifopis not a finite number. In this case,thisis not altered.
-
set
-
set
-
set
Set thisMPZto the number represented by the stringstrin the specifiedbase. See the GMP functionmpz_set_str.- Returns:
- 0 if the operation succeeded, -1 otherwise. In the latter case,
thisis not altered.
-
set
-
set
-
swap
-
initSet
-
initSet
Return anMPZwhose value isop. -
initSetUi
Return anMPZwhose value isop. -
initSet
Return anMPZwhose value is the truncation ofop.- Throws:
ArithmeticException- ifopis not a finite number.
-
initSet
Return anMPZwhose value is the number represented by the stringstrin the specifiedbase. See the GMP functionmpz_init_set_str.- Returns:
- a pair whose first component is
0if the operation succeeded, and-1if eitherbaseis not valid, orstris not a valid numeric representation in the specified base. The second component of the pair is the number represented instrif the operation succeeded,0otherwise.
-
getUi
public long getUi()Convert thisMPZto 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 thisMPZto 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 thisMPZto 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 thisMPZto a pair made of mantissa and exponent, truncating if necessary. See the GMP functionmpz_get_d_2exp. -
getStr
Return the String representation of thisMPZin the specifiedbase, ornullif the base is not valid. See the GMP functionmpz_get_str. -
getBigInteger
Converts thisMPZto BigInteger. -
addAssign
-
addAssign
-
add
-
addUiAssign
-
addUiAssign
-
addUi
Return anMPZwhose value is(this + op). -
subAssign
-
subAssign
-
sub
-
subUiAssign
-
subUiAssign
-
subUi
Return anMPZwhose value is(this - op). -
uiSubAssign
-
uiSubAssign
-
uiSub
Return anMPZwhose value is(op - this). -
mulAssign
-
mulAssign
-
mul
-
mulUiAssign
-
mulUiAssign
-
mulUi
Return anMPZwhose value is(this * op). -
mulAssign
-
mulAssign
-
mul
Return anMPZwhose value is(this * op). -
addmulAssign
-
addmul
-
addmulUiAssign
-
addmulUi
-
submulAssign
-
submul
-
submulUiAssign
-
submulUi
-
mul2ExpAssign
-
mul2ExpAssign
-
mul2Exp
Return anMPZwhose value is(this * 2b). -
negAssign
-
negAssign
-
neg
Return anMPZwhose value is the quotient of(- this). -
absAssign
-
absAssign
-
abs
Return anMPZwhose value is the absolute value ofthis. -
cdivqAssign
Set thisMPZto the quotient of the integer division(n / d), rounded towards +∞.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
cdivqAssign
Set thisMPZto the quotient of the integer division(this / d), rounded towards +∞.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
cdivrAssign
Set thisMPZto the remainder of the integer division(n / d), rounded towards +∞.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
cdivrAssign
Set thisMPZto the remainder of the integer division(this / d), rounded towards +∞.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
cdivqrAssign
Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards +∞.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.IllegalArgumentException- ifthisandrare the same object.
-
cdivqrAssign
Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards +∞.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.IllegalArgumentException- ifthisandrare the same object.
-
cdivqUiAssign
Set thisMPZto the quotient of the integer division(n / d), rounded towards +∞; it also Return the remainder.- Throws:
ArithmeticException- ifdis zero.
-
cdivqUiAssign
public long cdivqUiAssign(long d) Set thisMPZto the quotient of the integer division(this / d), rounded towards +∞; it also returns the remainder.- Throws:
ArithmeticException- ifdis zero.
-
cdivrUiAssign
Set thisMPZto the remainder of the integer division(n / d), rounded towards +∞; it also returns the remainder.- Throws:
ArithmeticException- ifdis zero.
-
cdivrUiAssign
public long cdivrUiAssign(long d) Set thisMPZto the remainder of the integer division(this / d), rounded towards +∞; it also returns the remainder.- Throws:
ArithmeticException- ifdis zero.
-
cdivqrUiAssign
Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards +∞; it also returns the remainder.- Throws:
ArithmeticException- ifdis zero.IllegalArgumentException- ifthisandrare the same object.
-
cdivqrUiAssign
Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards +∞; it also returns the remainder.- Throws:
ArithmeticException- ifdis zero.IllegalArgumentException- ifthisandrare the same object.
-
cdivUi
public long cdivUi(long d) Return the remainder of the integer division(this / d), rounded towards +∞.- Throws:
ArithmeticException- ifdis zero.
-
cdivq2ExpAssign
-
cdivq2ExpAssign
Set thisMPZto the quotient of the integer division(this / 2b), rounded toward +∞.- Returns:
- this
MPZ.
-
cdivr2ExpAssign
-
cdivr2ExpAssign
Set thisMPZto the remainder of the integer division(this / 2b), rounded toward +∞.- Returns:
- this
MPZ.
-
cdivq
Return anMPZwhose value is the quotient of the integer division(this / d), rounded towards +∞.- Throws:
ArithmeticException- ifdis zero.
-
cdivr
Return anMPZwhose value is the remainder of the integer division(this / d), rounded towards +∞.- Throws:
ArithmeticException- ifdis zero.
-
cdivqr
Return a pair ofMPZs whose values are the quotient and remainder of the integer division(this / d), rounded towards +∞.- Throws:
ArithmeticException- ifdis zero.
-
cdivq2Exp
Return anMPZwhose value is the quotient of the integer division(this / 2b), rounded towards +∞. -
cdivr2Exp
Return anMPZwhose value is the remainder of the integer division(this / 2b), rounded towards +∞. -
fdivqAssign
Set thisMPZto the quotient of the integer division(n / d), rounded towards -∞.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
fdivqAssign
Set thisMPZto the quotient of the integer division(this / d), rounded towards -∞.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
fdivrAssign
Set thisMPZto the remainder of the integer division(n / d), rounded towards -∞.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
fdivrAssign
Set thisMPZto the remainder of the integer division(this / d), rounded towards -∞.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
fdivqrAssign
Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards -∞.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.IllegalArgumentException- ifthisandrare the same object.
-
fdivqrAssign
Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards -∞.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.IllegalArgumentException- ifthisandrare the same object.
-
fdivqUiAssign
Set thisMPZto the quotient of the integer division(n / d), rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
ArithmeticException- ifdis zero.
-
fdivqUiAssign
public long fdivqUiAssign(long d) Set thisMPZto the quotient of the integer division(this / d), rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
ArithmeticException- ifdis zero.
-
fdivrUiAssign
Set thisMPZto the remainder of the integer division(n / d), rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
ArithmeticException- ifdis zero.
-
fdivrUiAssign
public long fdivrUiAssign(long d) Set thisMPZto the remainder of the integer division(this / d), rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
ArithmeticException- ifdis zero.
-
fdivqrUiAssign
Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
ArithmeticException- ifdis zero.IllegalArgumentException- ifthisandrare the same object.
-
fdivqrUiAssign
Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
ArithmeticException- ifdis zero.IllegalArgumentException- ifthisandrare the same object.
-
fdivUi
public long fdivUi(long d) Return the remainder of the integer division(this / d), rounded towards -∞.- Throws:
ArithmeticException- ifdis zero.
-
fdivq2ExpAssign
-
fdivq2ExpAssign
Set thisMPZto the quotient of the integer division(this / 2b), rounded toward -∞.- Returns:
- this
MPZ.
-
fdivr2ExpAssign
-
fdivr2ExpAssign
Set thisMPZto the remainder of the integer division(this / 2b), rounded toward -∞.- Returns:
- this
MPZ.
-
fdivq
Return anMPZwhose value is the quotient of the integer division(this / d), rounded towards -∞.- Throws:
ArithmeticException- ifdis zero.
-
fdivr
Return anMPZwhose value is the remainder of the integer division(this / d), rounded towards -∞.- Throws:
ArithmeticException- ifdis zero.
-
fdivqr
Return twoMPZs whose values are the quotient and remainder of the integer division(this / d), rounded towards -∞.- Throws:
ArithmeticException- ifdis zero.
-
fdivq2Exp
Return anMPZwhose value is the quotient of the integer division(this / 2b), rounded towards -∞. -
fdivr2Exp
Return anMPZwhose value is the remainder of the integer division(this / 2b), rounded towards -∞. -
tdivqAssign
Set thisMPZto the quotient of the integer division(n / d), rounded towards zero.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
tdivqAssign
Set thisMPZto the quotient of the integer division(this / d), rounded towards zero.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
tdivrAssign
Set thisMPZto the remainder of the integer division(n / d), rounded towards zero.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
tdivrAssign
Set thisMPZto the remainder of the integer division(this / d), rounded towards zero.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
tdivqrAssign
Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards zero.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.IllegalArgumentException- ifthisandrare the same object.
-
tdivqrAssign
Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards zero.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.IllegalArgumentException- ifthisandrare the same object.
-
tdivqUiAssign
Set thisMPZto the quotient of the integer division(n / d), rounded towards zero; it also returns the absolute value of the remainder.- Throws:
ArithmeticException- ifdis zero.
-
tdivqUiAssign
public long tdivqUiAssign(long d) Set thisMPZto the quotient of the integer division(this / d), rounded towards zero; it also returns the absolute value of the remainder.- Throws:
ArithmeticException- ifdis zero.
-
tdivrUiAssign
Set thisMPZto the remainder of the integer division(n / d), rounded towards zero; it also returns the absolute value of the remainder.- Throws:
ArithmeticException- ifdis zero.
-
tdivrUiAssign
public long tdivrUiAssign(long d) Set thisMPZto the remainder of the integer division(this / d), rounded towards zero; it also returns the absolute value of the remainder.- Throws:
ArithmeticException- ifdis zero.
-
tdivqrUiAssign
Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards zero; it also returns the absolute value of the remainder.- Throws:
ArithmeticException- ifdis zero.IllegalArgumentException- ifthisandrare the same object.
-
tdivqrUiAssign
Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards zero; it also returns the absolute value of the remainder.- Throws:
ArithmeticException- ifdis zero.IllegalArgumentException- ifthisandrare the same object.
-
tdivUi
public long tdivUi(long d) Return the remainder of the integer division(this / d), rounded towards zero.- Throws:
ArithmeticException- ifdis zero.
-
tdivq2ExpAssign
-
tdivq2ExpAssign
Set thisMPZto the quotient of the integer division(this / 2b), rounded toward zero.- Returns:
- this
MPZ.
-
tdivr2ExpAssign
-
tdivr2ExpAssign
Set thisMPZto the remainder of the integer division(this / 2b), rounded toward zero.- Returns:
- this
MPZ.
-
tdivq
Return anMPZwhose value is the quotient of the integer division(this / d), rounded towards zero.- Throws:
ArithmeticException- ifdis zero.
-
tdivr
Return anMPZwhose value is the remainder of the integer division(this / d), rounded towards zero.- Throws:
ArithmeticException- ifdis zero.
-
tdivqr
Return twoMPZs whose values are the quotient and remainder of the integer division(this / d), rounded towards zero.- Throws:
ArithmeticException- ifdis zero.
-
tdivq2Exp
Return anMPZwhose value is the quotient of the integer division(this / 2b), rounded towards zero. -
tdivr2Exp
Return anMPZwhose value is the remainder of the integer division(this / 2b), rounded towards zero. -
modAssign
Set thisMPZto(n mod d). The sign of the divisor is ignored, the result is always non-negative.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
modAssign
Set thisMPZto(this mod d). The sign of the divisor is ignored, the result is always non-negative.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
mod
-
modUiAssign
Set thisMPZto(n mod d); it also returns the result. The sign of the divisor is ignored, the result is always non-negative.- Throws:
ArithmeticException- ifdis zero.
-
modUiAssign
public long modUiAssign(long d) Set thisMPZto(n mod d); it also returns the result. The sign of the divisor is ignored, the result is always non-negative.- Throws:
ArithmeticException- ifdis zero.
-
modUi
public long modUi(long d) Return anMPZwhose value is(this mod d). The sign of the divisor is ignored, the result is always non-negative.- Throws:
ArithmeticException- ifdis zero.
-
divexactAssign
Set thisMPZto the quotient of(n / d). This method produces correct results only when it is known in advance thatddividesn.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
divexactAssign
Set thisMPZto the quotient of(this / d). This method produces correct results only when it is known in advance thatddividesthis.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
divexact
Return anMPZwhose value is the quotient of(this / d). This method produces correct results only when it is known in advance thatddividesthis.- Throws:
ArithmeticException- ifdis zero.
-
divexactUiAssign
Set thisMPZto the quotient of(n / d). This method produces correct results only when it is known in advance thatddividesn.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
divexactUiAssign
Set thisMPZto the quotient of(this / d). This method produces correct results only when it is known in advance thatddividesthis.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifdis zero.
-
divexactUi
Return anMPZwhose value is the quotient of(this / d). This method produces correct results only when it is known in advance thatddividesthis.- Throws:
ArithmeticException- ifdis zero.
-
isDivisible
Returntrueif and only ifthisis exactly divisible byd. This means that there exists an integerqsatisfying(n = q*d). Unlike the other division functions, the cased=0is accepted and following the rule it can be seen that only0is considered divisible by0. -
isDivisibleUi
public boolean isDivisibleUi(long d) Returntrueif and only ifthisis exactly divisible byd. This means that there exists an integerqsatisfying(n = q*d). The cased=0is accepted and following the rule it can be seen that only0is considered divisible by0. -
isDivisible2Exp
public boolean isDivisible2Exp(long b) Returntrueif and only ifthisis exactly divisible by2b. This means that there exists an integerqsatisfying(n = q * 2^b). -
isCongruent
Returntrueif and only ifthisis congruent tocmodulod. This means that there exists an integerqsatisfying(n = c + q*d). Unlike the other division functions,d=0is accepted and following the rule it can be seen thatnandcare considered congruent modulo0only when exactly equal. -
isCongruentUi
public boolean isCongruentUi(long c, long d) Returntrueif and only ifthisis congruent tocmodulod. This means that there exists an integerqsatisfying(n = c + q*d). Unlike the other division functions,d=0is accepted and following the rule it can be seen thatnandcare considered congruent modulo0only when exactly equal. -
isCongruent2Exp
Returntrueif and only ifthisis congruent tocmodulo2b. This means that there exists an integerqsatisfying(n = c + q*2^b). -
powmAssign
Set thisMPZto(baseexp)modulomod. Negativeexpis supported if the inverse ofbasemodulomodexists, otherwise anArithmeticExpectionis thrown.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifmodis zero orbasehas no inverse modulomod.
-
powmAssign
Set thisMPZto(thisexp)modulomod.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifmodis zero.
-
powm
-
powmUiAssign
Set thisMPZto(baseexp)modulomod.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifmodis zero.
-
powmUiAssign
Set thisMPZto(thisexp)modulomod.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifmodis zero.
-
powmUi
-
powmSecAssign
Set thisMPZto(baseexp)modulomod. It is required that(exp > 0and thatmodis odd. This function is intended for cryptographic purposes, where resilience to side-channel attacks is desired.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifmodis even orexpis negative.
-
powmSecAssign
Set thisMPZto(thisexp)modulomod. It is required that(exp > 0and thatmodis odd. This function is intended for cryptographic purposes, where resilience to side-channel attacks is desired.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifmodis zero.
-
powmSec
-
powUiAssign
-
powUiAssign
Set thisMPZto(thisexp). The case00yields1.- Returns:
- this
MPZ.
-
powUi
Return anMPZwhose value is(thisexp). The case00yields1. -
powUiAssign
Set thisMPZto(baseexp). The case00yields1.- Returns:
- this
MPZ.
-
powUi
Return anMPZwhose value is(baseexp). The case00yields1. -
rootAssign
Set thisMPZto the truncated integer part of thenth 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 thisMPZto the truncated integer part of itsnth root.- Returns:
- true if the computation is exact.
- Throws:
ArithmeticException- if n is even and this is negative.
-
root
Return anMPZwhose value is the truncated integer part of thenth 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 thisMPZto the truncated integer part of thenth root ofuandremto the remainder, i.e.,(u - rootn).- Returns:
- this
MPZ. - Throws:
ArithmeticException- if n is even and u is negative.
-
rootremAssign
Set thisMPZto the truncated integer part of the itsnth root andremto the remainder, i.e.,(this - rootn).- Returns:
- this
MPZ. - Throws:
ArithmeticException- if n is even and this is negative.
-
rootrem
Return twoMPZs whose values are the truncated integer part of thenth root ofthisand the remainder, i.e.,(u - rootn).- Throws:
ArithmeticException- if n is even and this is negative.
-
sqrtAssign
Set thisMPZto the truncated integer part of the square root ofop.- Returns:
- this
MPZ. - Throws:
ArithmeticException- if op is negative.
-
sqrtAssign
Set thisMPZto the truncated integer part of its square root.- Returns:
- this
MPZ. - Throws:
ArithmeticException- if this is negative.
-
sqrt
Return anMPZwhose value is the truncated integer part of the square root ofthis.- Throws:
ArithmeticException- if this is negative.
-
sqrtremAssign
Set thisMPZto the truncated integer part of the square root ofopandremto the remainder, i.e.,(op - root2).- Returns:
- this
MPZ. - Throws:
ArithmeticException- if op is negative.
-
sqrtremAssign
Set thisMPZto the truncated integer part of its square root andremto the remainder, i.e.,(this - root2).- Returns:
- this
MPZ. - Throws:
ArithmeticException- if this is negative.
-
sqrtrem
Return twoMPZs whose values are the truncated integer part of the square root ofthisand the remainder, i.e.,(op - root2).- Throws:
ArithmeticException- if this is negative.
-
isPerfectPower
public boolean isPerfectPower()Returntrueif and only if this number is a perfect power, i.e., if there exist integersaandb, with(b > 1), such thatthisequals(ab). Under this definition both0and1are considered to be perfect powers. Negative values are accepted, but of course can only be odd perfect powers. -
isPerfectSquare
public boolean isPerfectSquare()Returntrueif and only if this number is a perfect square. Under this definition both0and1are 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.PrimalityStatusenum, telling whetherthisis definitely prime, probably prime or definitely non-prime.
-
nextprimeAssign
-
nextprimeAssign
Set thisMPZto 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
-
gcdAssign
-
gcdAssign
-
gcd
-
gcdUiAssign
Set thisMPZto the greatest commond divisor ofop1andop2, 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 thisMPZto the greatest commond divisor ofop1andop2, 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 ofthisandop. If the result does not fit into an unsigned long, 0 is returned. -
gcdextAssign
-
gcdextAssign
Set thisMPZto the greatest common divisor ofthisandop, and in addition Setsandtto coefficients satisfying(this*s + op*t = gcd). Ifsortis null, that value is not computed. See the GMP functionmpz_gcdext. -
gcdext
Return the greatest common divisor ofthisandop, together with numberssandtsatisfying(a*this + b*op = g)See the GMP functionmpz_gcdext. -
lcmAssign
-
lcmAssign
-
lcm
-
lcmUiAssign
-
lcmUiAssign
-
lcmUi
-
invertAssign
-
invertAssign
Set thisMPZto the inverse ofthismoduloop. If the inverse does not exist, the new value of thisMPZis undefined.- Returns:
- true if the inverse exists, false otherwise.
-
invert
-
jacobi
Return the Jacobi symbol(this / b). This is defined only forbodd. -
legendre
Return the Legendre symbol(this / p). This is defined only forpan odd positive prime, and for suchpit’s identical to the Jacobi symbol. -
kronecker
Return the Jacobi symbol(this / n)with the Kronecker extension(this/2)=(2/this)whenthisis odd, or(this/2)=0whenthisis even. Whenbis 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
-
removeAssign
Remove all occurrences of the factorffromthisMPZ. The return value is the number of occurrences offwhich were removed. -
remove
-
facUiAssign
Set thisMPZto the factorial ofn. -
facUi
Return anMPZwhose value is the factorial ofn. -
dfacUiAssign
Set thisMPZto the double factorial ofn. -
dfacUi
Return anMPZwhose value the double factorial ofn. -
mfacUiUiAssign
Set thisMPZto them-multi factorial ofn. -
mfacUiUi
Return anMPZwhose value is them-multi factorial ofn. -
primorialUiAssign
Set thisMPZto the primorial ofn, i.e., the product of all positive prime numbers<= n. -
primorialUi
Return anMPZwhose value is the primorial ofn, i.e., the product of all positive prime numbers<= n. -
binUiAssign
-
binUiAssign
Set thisMPZto the binomial coefficientthisoverk. Negative values ofthisare 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 anMPZwhose value is the binomial coefficientthisoverk. Negative values ofthisare supported as inbinUiAssign(it.unich.jgmp.MPZ,long). -
binUiUiAssign
Set thisMPZto the binomial coefficientnoverk. -
binUiUi
Return anMPZwhose value is the binomial coefficientnoverk. -
fibUiAssign
Set thisMPZto then-th Fibonacci number. -
fibUi
Return anMPZwhose value is then-th Fibonacci number. -
fib2UiAssign
-
fib2Ui
-
lucnumUiAssign
Set thisMPZto then-th Lucas number. -
lucnumUi
Return anMPZwhose value is then-th Lucas number. -
lucnum2UiAssign
-
lucnum2Ui
-
cmp
Comparethiswithop. Return a positive value if(this > op), zero ifthis = op, or a negative value ifthis < op. -
cmp
public int cmp(double op) Comparethiswithop. Return a positive value if(this > op), zero ifthis = op, or a negative value ifthis < op. The value ofopmay be infinite, but the result is undefined on NaNs.- Throws:
ArithmeticException- ifopis a NaN.
-
cmp
public int cmp(long op) Comparethiswithop. Return a positive value if(this > op), zero ifthis = op, or a negative value ifthis < op. -
cmpUi
public int cmpUi(long op) Comparethiswithop. Return a positive value if(this > op), zero ifthis = op, or a negative value ifthis < op. -
cmpabs
Compare the absolute values ofthisandop. 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 ofthisandop. Return a positive value if(abs(this) > abs(op)), zero ifabs(this) = abs(op), or a negative value ifabs(this) < abs(op). The value ofopmay be infinite, but the result is undefined on NaNs.- Throws:
ArithmeticException- ifopis a NaN.
-
cmpabsUi
public int cmpabsUi(long op) Compare the absolute values ofthisandop. 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+1if(this > 0),0if(this = 0)and-1ifthis < 0. -
andAssign
-
andAssign
-
and
-
iorAssign
-
iorAssign
-
ior
-
xorAssign
-
xorAssign
-
xor
-
comAssign
-
comAssign
Set thisMPZto(~ this). -
com
Return anMPZwhose value is(~ op). -
popcount
public long popcount()If thisMPZis non-negative, return its population count, which is the number of1bits in its binary representation. If thisMPZis negative, the number of1s is infinite, and the return value is the largest possible value for the native typemp_bitcnt_t. -
hamdist
Ifthisandopare both>= 0or both< 0, return the Hamming distance between them, which is the number of bit positions wherethisandophave different bit values. If one operand is>= 0and the other< 0then 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 first0bit 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 first1bit is found. Return the index of the found bit. -
setbitAssign
Set the bitindexof thisMPZ. -
setbit
Return anMPZwhose value is(this | 2index). -
clrbitAssign
Clear the bitindexof thisMPZ. -
clrbit
Return anMPZwhose value is(this & ~ 2index). -
combitAssign
Complement the bitindexof thisMPZ. -
combit
Return anMPZwhose value is(this ^ 2index). -
tstbit
public int tstbit(long index) Return the bitindexof thisMPZ. -
urandombAssign
-
urandomb
-
urandommAssign
-
urandomm
-
rrandombAssign
Set thisMPZto 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 anMPZwhose 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 thisMPZto a random integer of at mostmax_sizelimbs. The generated random number doesn’t satisfy any particular requirements of randomness. Negative random numbers are generated whenmax_sizeis 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 anMPZwhose value is a random integer of at mostmax_sizelimbs. The generated random number doesn’t satisfy any particular requirements of randomness. Negative random numbers are generated whenmax_sizeis negative. -
random2Assign
Deprecated.userrandombAssign(it.unich.jgmp.RandState,long)instead, since this method uses a global random state and it is not reentrant.Set thisMPZto a random integer of at mostmax_sizelimbs, 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_sizeis 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 anMPZwhose value is a random integer of at mostmax_sizelimbs, 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_sizeis negative. -
bufferImportAssign
Set thisMPZfrom the buffer of word data atop. See the detailed description in the documentation of the GMP functionmpz_import. The parametercountin the prototype ofmpz_importis automatically computed by the capacity of the bufferop. Thesizeparameter is declared asintinstead oflongsince Java does not allow byte buffers to be longer than 4GB. -
bufferImport
Return anMPZwhose value is determined from the buffer of word data atop. Thesizeparameter is declared asintinstead oflongsince Java does not allow byte buffers to be longer than 4GB.- See Also:
-
bufferExport
Return aByteBufferfilled 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 outputcountof the original GMP function is not needed, since it corresponds to the capacity of the resultingByteBuffer. Thesizeparameter is declared asintinstead oflongsince Java does not allow byte buffers to be longer than 4GB. -
fitsUlong
public boolean fitsUlong()Returntrueif and only if thisMPZfits into a native unsigned long. -
fitsSlong
public boolean fitsSlong()Returntrueif and only if thisMPZfits into a native signed long. -
fitsUint
public boolean fitsUint()Returntrueif and only if thisMPZfits into a native unsigned int. -
fitsSint
public boolean fitsSint()Returntrueif and only if thisMPZfits into a native signed int. -
fitsUshort
public boolean fitsUshort()Returntrueif and only if thisMPZfits into a native unsigned short. -
fitsSshort
public boolean fitsSshort()Returntrueif and only if thisMPZfits into a native signed short. -
isOdd
public boolean isOdd()Returntrueif and only if thisMPZis odd. -
isEven
public boolean isEven()Returntrueif and only if thisMPZis even -
isZero
public boolean isZero()Returntrueif and only if thisMPZis zero. -
sizeinbase
public long sizeinbase(int base) Return the size of thisMPZmeasured in number of digits in the specifiedbase. See the the GMP functionmpz_sizeinbase.- Throws:
IllegalArgumentException- if base is not between 2 and 62.
-
setValue
-
setValue
-
setValue
Set thisMPZto the truncation opop.- Returns:
- this
MPZ. - Throws:
ArithmeticException- ifopis not a finite number. In this case,thisis not altered.
-
setValue
-
setValue
-
setValue
Set thisMPZto the number represented by the stringstrin the specifiedbase. See the GMP functionmpz_set_str.- Throws:
NumberFormatException- if eitherbaseis not valid orstris not a valid number representation in the specified base. In this case,thisis not altered.
-
setValue
Set thisMPZto the value represented by the stringstrin decimal base.- Throws:
NumberFormatException- ifstris not a valid number representation in decimal base.- See Also:
-
setValue
-
compareTo
Compare thisMPZwithop. Return a positive value if(this > op), zero ifthis = op, or a negative value ifthis < op. This order is compatible with equality.- Specified by:
compareToin interfaceComparable<MPZ>
-
equals
-
hashCode
-
longValue
-
intValue
-
doubleValue
public double doubleValue()Convert thisMPZto 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:
doubleValuein classNumber
-
floatValue
public float floatValue()Convert thisMPZto a float, truncating if necessary.- Specified by:
floatValuein classNumber
-
toString
Convert thisMPZto its string representation in the specifiedbase, ornullif the base is not valid. See the GMP functionmpz_get_str. -
toString
-
writeObject
- Throws:
IOException
-
readObject
- Throws:
IOExceptionClassNotFoundException
-
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.