Package it.unich.jgmp

Class MPZ

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<MPZ>

    public class MPZ
    extends java.lang.Number
    implements java.lang.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:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private MpzT mpzNative
      The pointer to the native mpz_t object.
      private static long serialVersionUID
      Version for serializability.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        MPZ()
      Build an MPZ whose value is zero.
        MPZ​(double op)
      Build an MPZ whose value is the truncation of op.
        MPZ​(long op)
      Build an MPZ whose value is op.
        MPZ​(MPF op)
      Build an MPZ whose value is the truncation of op.
        MPZ​(MPQ op)
      Build an MPZ whose value is the truncation of op.
        MPZ​(MPZ op)
      Build an MPZ whose value is op.
      private MPZ​(MpzT pointer)
      A private constructor which build an MPZ starting from a pointer to its native data object.
        MPZ​(java.lang.String str)
      Build an MPZ whose value is the number represented by the string str in decimal base.
        MPZ​(java.lang.String str, int base)
      Build an MPZ whose value is the number represented by the string str in the specified base.
        MPZ​(java.math.BigInteger op)
      Builds an MPZ whose value is the same as op.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      MPZ abs()
      Return an MPZ whose value is the absolute value of this.
      MPZ absAssign()
      Set this MPZ to its absolute value.
      MPZ absAssign​(MPZ op)
      Set this MPZ to the absolute value of op.
      MPZ add​(MPZ op)
      Return an MPZ whose value is (this + op).
      MPZ addAssign​(MPZ op)
      Set this MPZ to (this + op)
      MPZ addAssign​(MPZ op1, MPZ op2)
      Set this MPZ to (op1 + op2).
      MPZ addmul​(MPZ op1, MPZ op2)
      Return an MPZ whose value is (this + op1 * op2).
      MPZ addmulAssign​(MPZ op1, MPZ op2)
      Add (op1 * op2) to this MPZ.
      MPZ addmulUi​(MPZ op1, long op2)
      Return an MPZ whose value is (this + op1 * op2).
      MPZ addmulUiAssign​(MPZ op1, long op2)
      Add (op1 * op2) to this MPZ.
      MPZ addUi​(long op)
      Return an MPZ whose value is (this + op).
      MPZ addUiAssign​(long op)
      Set this MPZ to (this + op)
      MPZ addUiAssign​(MPZ op1, long op2)
      Set this MPZ to (op1 + op2).
      MPZ and​(MPZ op)
      Return an MPZ whose value is (this & op).
      MPZ andAssign​(MPZ op)
      Set this MPZ to (this & op).
      MPZ andAssign​(MPZ op1, MPZ op2)
      Set this MPZ to (op1 & op2).
      MPZ binUi​(long k)
      Return an MPZ whose value is the binomial coefficient this over k.
      MPZ binUiAssign​(long k)
      Set this MPZ to the binomial coefficient this over k.
      MPZ binUiAssign​(MPZ n, long k)
      Set this MPZ to the binomial coefficient n over k.
      static MPZ binUiUi​(long n, long k)
      Return an MPZ whose value is the binomial coefficient n over k.
      MPZ binUiUiAssign​(long n, long k)
      Set this MPZ to the binomial coefficient n over k.
      java.nio.ByteBuffer bufferExport​(int order, int size, int endian, long nails)
      Return a ByteBuffer filled with word data from this MPZ.
      static MPZ bufferImport​(int order, int size, int endian, long nails, java.nio.ByteBuffer op)
      Return an MPZ whose value is determined from the buffer of word data at op.
      MPZ bufferImportAssign​(int order, int size, int endian, long nails, java.nio.ByteBuffer op)
      Set this MPZ from the buffer of word data at op.
      MPZ cdivq​(MPZ d)
      Return an MPZ whose value is the quotient of the integer division (this / d), rounded towards +∞.
      MPZ cdivq2Exp​(long b)
      Return an MPZ whose value is the quotient of the integer division (this / 2b), rounded towards +∞.
      MPZ cdivq2ExpAssign​(long b)
      Set this MPZ to the quotient of the integer division (this / 2b), rounded toward +∞.
      MPZ cdivq2ExpAssign​(MPZ n, long b)
      Set this MPZ to the quotient of the integer division (n / 2b), rounded toward +∞.
      MPZ cdivqAssign​(MPZ d)
      Set this MPZ to the quotient of the integer division (this / d), rounded towards +∞.
      MPZ cdivqAssign​(MPZ n, MPZ d)
      Set this MPZ to the quotient of the integer division (n / d), rounded towards +∞.
      org.javatuples.Pair<MPZ,​MPZ> cdivqr​(MPZ d)
      Return a pair of MPZs whose values are the quotient and remainder of the integer division (this / d), rounded towards +∞.
      MPZ cdivqrAssign​(MPZ r, MPZ d)
      Set this MPZ and r to the quotient and remainder of the integer division (this / d), rounded towards +∞.
      MPZ cdivqrAssign​(MPZ r, MPZ n, MPZ d)
      Set this MPZ and r to the quotient and remainder of the integer division (n / d), rounded towards +∞.
      long cdivqrUiAssign​(MPZ r, long d)
      Set this MPZ and r 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 this MPZ and r to the quotient and remainder of the integer division (n / d), rounded towards +∞; it also returns the remainder.
      long cdivqUiAssign​(long d)
      Set this MPZ to the quotient of the integer division (this / d), rounded towards +∞; it also returns the remainder.
      long cdivqUiAssign​(MPZ n, long d)
      Set this MPZ to the quotient of the integer division (n / d), rounded towards +∞; it also Return the remainder.
      MPZ cdivr​(MPZ d)
      Return an MPZ whose value is the remainder of the integer division (this / d), rounded towards +∞.
      MPZ cdivr2Exp​(long b)
      Return an MPZ whose value is the remainder of the integer division (this / 2b), rounded towards +∞.
      MPZ cdivr2ExpAssign​(long b)
      Set this MPZ to the remainder of the integer division (this / 2b), rounded toward +∞.
      MPZ cdivr2ExpAssign​(MPZ n, long b)
      Set this MPZ to the remainder of the integer division (n / 2b), rounded toward +∞.
      MPZ cdivrAssign​(MPZ d)
      Set this MPZ to the remainder of the integer division (this / d), rounded towards +∞.
      MPZ cdivrAssign​(MPZ n, MPZ d)
      Set this MPZ to the remainder of the integer division (n / d), rounded towards +∞.
      long cdivrUiAssign​(long d)
      Set this MPZ to the remainder of the integer division (this / d), rounded towards +∞; it also returns the remainder.
      long cdivrUiAssign​(MPZ n, long d)
      Set this MPZ 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 +∞.
      MPZ clrbit​(long index)
      Return an MPZ whose value is (this & ~ 2index).
      MPZ clrbitAssign​(long index)
      Clear the bit index of this MPZ.
      int cmp​(double op)
      Compare this with op.
      int cmp​(long op)
      Compare this with op.
      int cmp​(MPZ op)
      Compare this with op.
      int cmpabs​(double op)
      Compare the absolute values of this and op.
      int cmpabs​(MPZ op)
      Compare the absolute values of this and op.
      int cmpabsUi​(long op)
      Compare the absolute values of this and op.
      int cmpUi​(long op)
      Compare this with op.
      MPZ com()
      Return an MPZ whose value is (~ op).
      MPZ comAssign()
      Set this MPZ to (~ this).
      MPZ comAssign​(MPZ op)
      Set this MPZ to (~ op).
      MPZ combit​(long index)
      Return an MPZ whose value is (this ^ 2index).
      MPZ combitAssign​(long index)
      Complement the bit index of this MPZ.
      int compareTo​(MPZ op)
      Compare this MPZ with op.
      static MPZ dfacUi​(long n)
      Return an MPZ whose value the double factorial of n.
      MPZ dfacUiAssign​(long n)
      Set this MPZ to the double factorial of n.
      MPZ divexact​(MPZ d)
      Return an MPZ whose value is the quotient of (this / d).
      MPZ divexactAssign​(MPZ d)
      Set this MPZ to the quotient of (this / d).
      MPZ divexactAssign​(MPZ n, MPZ d)
      Set this MPZ to the quotient of (n / d).
      MPZ divexactUi​(long d)
      Return an MPZ whose value is the quotient of (this / d).
      MPZ divexactUiAssign​(long d)
      Set this MPZ to the quotient of (this / d).
      MPZ divexactUiAssign​(MPZ n, long d)
      Set this MPZ to the quotient of (n / d).
      double doubleValue()
      Convert this MPZ to a double, truncating if necessary.
      boolean equals​(java.lang.Object obj)
      Compare this MPZ with the object op for equality.
      static MPZ facUi​(long n)
      Return an MPZ whose value is the factorial of n.
      MPZ facUiAssign​(long n)
      Set this MPZ to the factorial of n.
      MPZ fdivq​(MPZ d)
      Return an MPZ whose value is the quotient of the integer division (this / d), rounded towards -∞.
      MPZ fdivq2Exp​(long b)
      Return an MPZ whose value is the quotient of the integer division (this / 2b), rounded towards -∞.
      MPZ fdivq2ExpAssign​(long b)
      Set this MPZ to the quotient of the integer division (this / 2b), rounded toward -∞.
      MPZ fdivq2ExpAssign​(MPZ n, long b)
      Set this MPZ to the quotient of the integer division (n / 2b), rounded toward -∞.
      MPZ fdivqAssign​(MPZ d)
      Set this MPZ to the quotient of the integer division (this / d), rounded towards -∞.
      MPZ fdivqAssign​(MPZ n, MPZ d)
      Set this MPZ to the quotient of the integer division (n / d), rounded towards -∞.
      org.javatuples.Pair<MPZ,​MPZ> fdivqr​(MPZ d)
      Return two MPZs whose values are the quotient and remainder of the integer division (this / d), rounded towards -∞.
      MPZ fdivqrAssign​(MPZ r, MPZ d)
      Set this MPZ and r to the quotient and remainder of the integer division (this / d), rounded towards -∞.
      MPZ fdivqrAssign​(MPZ r, MPZ n, MPZ d)
      Set this MPZ and r to the quotient and remainder of the integer division (n / d), rounded towards -∞.
      long fdivqrUiAssign​(MPZ r, long d)
      Set this MPZ and r 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 this MPZ and r 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 this MPZ 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 this MPZ to the quotient of the integer division (n / d), rounded towards -∞; it also returns the absolute value of the remainder.
      MPZ fdivr​(MPZ d)
      Return an MPZ whose value is the remainder of the integer division (this / d), rounded towards -∞.
      MPZ fdivr2Exp​(long b)
      Return an MPZ whose value is the remainder of the integer division (this / 2b), rounded towards -∞.
      MPZ fdivr2ExpAssign​(long b)
      Set this MPZ to the remainder of the integer division (this / 2b), rounded toward -∞.
      MPZ fdivr2ExpAssign​(MPZ n, long b)
      Set this MPZ to the remainder of the integer division (n / 2b), rounded toward -∞.
      MPZ fdivrAssign​(MPZ d)
      Set this MPZ to the remainder of the integer division (this / d), rounded towards -∞.
      MPZ fdivrAssign​(MPZ n, MPZ d)
      Set this MPZ to the remainder of the integer division (n / d), rounded towards -∞.
      long fdivrUiAssign​(long d)
      Set this MPZ 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 this MPZ 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 -∞.
      static org.javatuples.Pair<MPZ,​MPZ> fib2Ui​(long n)
      Return two MPZ whose values are the n-th and (n-1)-th Fibonacci numbers.
      MPZ fib2UiAssign​(MPZ fnsub1, long n)
      Set the value of this and fnsub1 to the n-th and (n-1)-th Fibonacci numbers respecively.
      static MPZ fibUi​(long n)
      Return an MPZ whose value is the n-th Fibonacci number.
      MPZ fibUiAssign​(long n)
      Set this MPZ to the n-th Fibonacci number.
      boolean fitsSint()
      Return true if and only if this MPZ fits into a native signed int.
      boolean fitsSlong()
      Return true if and only if this MPZ fits into a native signed long.
      boolean fitsSshort()
      Return true if and only if this MPZ fits into a native signed short.
      boolean fitsUint()
      Return true if and only if this MPZ fits into a native unsigned int.
      boolean fitsUlong()
      Return true if and only if this MPZ fits into a native unsigned long.
      boolean fitsUshort()
      Return true if and only if this MPZ fits into a native unsigned short.
      float floatValue()
      Convert this MPZ to a float, truncating if necessary.
      MPZ gcd​(MPZ op)
      Return an MPZ whose value is the greatest commond divisor of this and op.
      MPZ gcdAssign​(MPZ op)
      Set this MPZ to the greatest commond divisor of this and op.
      MPZ gcdAssign​(MPZ op1, MPZ op2)
      Set this MPZ to the greatest commond divisor of op1 and op2.
      org.javatuples.Triplet<MPZ,​MPZ,​MPZ> gcdext​(MPZ op)
      Return the greatest common divisor of this and op, together with numbers s and t satisfying (a*this + b*op = g) See the GMP function mpz_gcdext.
      MPZ gcdextAssign​(MPZ s, MPZ t, MPZ op)
      Set this MPZ to the greatest common divisor of this and op, and in addition Set s and t to coefficients satisfying (this*s + op*t = gcd).
      MPZ gcdextAssign​(MPZ s, MPZ t, MPZ a, MPZ b)
      Set this MPZ to the greatest common divisor of a and b, and in addition Set s and t to coefficients satisfying (a*s + b*t = gcd).
      long gcdUi​(long op)
      Return the greatest commond divisor of this and op.
      long gcdUiAssign​(long op)
      Set this MPZ to the greatest commond divisor of op1 and op2, and returns it.
      long gcdUiAssign​(MPZ op1, long op2)
      Set this MPZ to the greatest commond divisor of op1 and op2, and return it.
      java.math.BigInteger getBigInteger()
      Converts this MPZ to BigInteger.
      double getD()
      Convert this MPZ to a double, truncating if necessary.
      org.javatuples.Pair<java.lang.Double,​java.lang.Long> getD2Exp()
      Convert this MPZ to a pair made of mantissa and exponent, truncating if necessary.
      MpzT getNative()
      Return the native pointer to the GMP object.
      long getSi()
      Convert this MPZ to a signed long.
      java.lang.String getStr​(int base)
      Return the String representation of this MPZ in the specified base, or null if the base is not valid.
      long getUi()
      Convert this MPZ to an unsigned long.
      long hamdist​(MPZ op)
      If this and op are both >= 0 or both < 0, return the Hamming distance between them, which is the number of bit positions where this and op have different bit values.
      int hashCode()
      Return a hash code value for this MPZ.
      static MPZ init()
      Return an MPZ whose value is zero.
      static MPZ init2​(long n)
      Return an MPZ whose value is zero, with pre-allocated space for n-bit numbers.
      static MPZ initSet​(double op)
      Return an MPZ whose value is the truncation of op.
      static MPZ initSet​(long op)
      Return an MPZ whose value is op.
      static MPZ initSet​(MPZ op)
      Return an MPZ whose value is op.
      static org.javatuples.Pair<java.lang.Integer,​MPZ> initSet​(java.lang.String str, int base)
      Return an MPZ whose value is the number represented by the string str in the specified base.
      static MPZ initSetUi​(long op)
      Return an MPZ whose value is op.
      int intValue()
      Convert this MPZ to a signed int, truncating if necessary.
      java.util.Optional<MPZ> invert​(MPZ op)
      Optionally return, when it exists, an MPZ whose value is the inverse of this modulo op.
      boolean invertAssign​(MPZ op)
      Set this MPZ to the inverse of this modulo op.
      boolean invertAssign​(MPZ op1, MPZ op2)
      Set this MPZ to the inverse of op1 modulo op2.
      MPZ ior​(MPZ op)
      Return an MPZ whose value is (this | op).
      MPZ iorAssign​(MPZ op)
      Set this MPZ to (this | op).
      MPZ iorAssign​(MPZ op1, MPZ op2)
      Set this MPZ to (op1 | op2).
      boolean isCongruent​(MPZ c, MPZ d)
      Return true if and only if this is congruent to c modulo d.
      boolean isCongruent2Exp​(MPZ c, long b)
      Return true if and only if this is congruent to c modulo 2b.
      boolean isCongruentUi​(long c, long d)
      Return true if and only if this is congruent to c modulo d.
      boolean isDivisible​(MPZ d)
      Return true if and only if this is exactly divisible by d.
      boolean isDivisible2Exp​(long b)
      Return true if and only if this is exactly divisible by 2b.
      boolean isDivisibleUi​(long d)
      Return true if and only if this is exactly divisible by d.
      boolean isEven()
      Return true if and only if this MPZ is even
      boolean isOdd()
      Return true if and only if this MPZ is odd.
      boolean isPerfectPower()
      Return true if and only if this number is a perfect power, i.e., if there exist integers a and b, with (b > 1), such that this equals (ab).
      boolean isPerfectSquare()
      Return true if and only if this number is a perfect square.
      MPZ.PrimalityStatus isProbabPrime​(int reps)
      Return true if and only if this is prime.
      boolean isZero()
      Return true if and only if this MPZ is zero.
      int jacobi​(MPZ b)
      Return the Jacobi symbol (this / b).
      int kronecker​(long b)
      Return the Jacobi symbol (this / b) with the Kronecker extension.
      int kronecker​(MPZ b)
      Return the Jacobi symbol (this / n) with the Kronecker extension (this/2)=(2/this) when this is odd, or (this/2)=0 when this 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.
      MPZ lcm​(MPZ op)
      Return an MPZ whose value is the least common multiple of this and op.
      MPZ lcmAssign​(MPZ op)
      Set this MPZ to the least common multiple of this and op.
      MPZ lcmAssign​(MPZ op1, MPZ op2)
      Set this MPZ to the least common multiple of op1 and op2.
      MPZ lcmUi​(long op)
      Return the least common multiple of this and op.
      MPZ lcmUiAssign​(long op)
      Set this MPZ to the least common multiple of this and op.
      MPZ lcmUiAssign​(MPZ op1, long op2)
      Set this MPZ to the least common multiple of op1 and op2.
      int legendre​(MPZ p)
      Return the Legendre symbol (this / p).
      long longValue()
      Convert this MPZ to a signed long.
      static org.javatuples.Pair<MPZ,​MPZ> lucnum2Ui​(long n)
      Return two MPZ whose values are the n-th and (n-1)-th Lucas numbers.
      MPZ lucnum2UiAssign​(MPZ fnsub1, long n)
      Set the value of this and fnsub1 to the n-th and (n-1)-th Lucas numbers respecively.
      static MPZ lucnumUi​(long n)
      Return an MPZ whose value is the n-th Lucas number.
      MPZ lucnumUiAssign​(long n)
      Set this MPZ to the n-th Lucas number.
      static MPZ mfacUiUi​(long n, long m)
      Return an MPZ whose value is the m-multi factorial of n.
      MPZ mfacUiUiAssign​(long n, long m)
      Set this MPZ to the m-multi factorial of n.
      MPZ mod​(MPZ d)
      Return an MPZ whose value is (this mod d).
      MPZ modAssign​(MPZ d)
      Set this MPZ to (this mod d).
      MPZ modAssign​(MPZ n, MPZ d)
      Set this MPZ to (n mod d).
      long modUi​(long d)
      Return an MPZ whose value is (this mod d).
      long modUiAssign​(long d)
      Set this MPZ to (n mod d); it also returns the result.
      long modUiAssign​(MPZ n, long d)
      Set this MPZ to (n mod d); it also returns the result.
      MPZ mul​(long op)
      Return an MPZ whose value is (this * op).
      MPZ mul​(MPZ op)
      Return an MPZ whose value is (this * op).
      MPZ mul2Exp​(long b)
      Return an MPZ whose value is (this * 2b).
      MPZ mul2ExpAssign​(long b)
      Set this MPZ to (this * 2b).
      MPZ mul2ExpAssign​(MPZ op, long b)
      Set this MPZ to (op * 2b).
      MPZ mulAssign​(long op)
      Set this MPZ to (this * op)
      MPZ mulAssign​(MPZ op)
      Set this MPZ to (this * op)
      MPZ mulAssign​(MPZ op1, long op2)
      Set this MPZ to (op1 * op2).
      MPZ mulAssign​(MPZ op1, MPZ op2)
      Set this MPZ to (op1 * op2).
      MPZ mulUi​(long op)
      Return an MPZ whose value is (this * op).
      MPZ mulUiAssign​(long op)
      Set this MPZ to (this * op)
      MPZ mulUiAssign​(MPZ op1, long op2)
      Set this MPZ to (op1 * op2).
      MPZ neg()
      Return an MPZ whose value is the quotient of (- this).
      MPZ negAssign()
      Set this MPZ to its opposite.
      MPZ negAssign​(MPZ op)
      Set this MPZ to (- op).
      MPZ nextprime()
      Return an MPZ whose value is the next prime greater then this.
      MPZ nextprimeAssign()
      Set this MPZ to the next prime greater then itself.
      MPZ nextprimeAssign​(MPZ op)
      Set this MPZ to the next prime greater then op.
      long popcount()
      If this MPZ is non-negative, return its population count, which is the number of 1 bits in its binary representation.
      MPZ powm​(MPZ exp, MPZ mod)
      Return an MPZ whose value is (thisexp) modulo mod.
      MPZ powmAssign​(MPZ exp, MPZ mod)
      Set this MPZ to (thisexp) modulo mod.
      MPZ powmAssign​(MPZ base, MPZ exp, MPZ mod)
      Set this MPZ to (baseexp) modulo mod.
      MPZ powmSec​(MPZ exp, MPZ mod)
      Return an MPZ whose value is (thisexp) modulo mod.
      MPZ powmSecAssign​(MPZ exp, MPZ mod)
      Set this MPZ to (thisexp) modulo mod.
      MPZ powmSecAssign​(MPZ base, MPZ exp, MPZ mod)
      Set this MPZ to (baseexp) modulo mod.
      MPZ powmUi​(long exp, MPZ mod)
      Return an MPZ whose value is (thisexp) modulo mod.
      MPZ powmUiAssign​(long exp, MPZ mod)
      Set this MPZ to (thisexp) modulo mod.
      MPZ powmUiAssign​(MPZ base, long exp, MPZ mod)
      Set this MPZ to (baseexp) modulo mod.
      MPZ powUi​(long exp)
      Return an MPZ whose value is (thisexp).
      static MPZ powUi​(long base, long exp)
      Return an MPZ whose value is (baseexp).
      MPZ powUiAssign​(long exp)
      Set this MPZ to (thisexp).
      MPZ powUiAssign​(long base, long exp)
      Set this MPZ to (baseexp).
      MPZ powUiAssign​(MPZ base, long exp)
      Set this MPZ to (baseexp).
      static MPZ primorialUi​(long n)
      Return an MPZ whose value is the primorial of n, i.e., the product of all positive prime numbers <= n.
      MPZ primorialUiAssign​(long n)
      Set this MPZ to the primorial of n, i.e., the product of all positive prime numbers <= n.
      static MPZ random​(long max_size)
      Deprecated.
      use urandomb(it.unich.jgmp.RandState,long) or urandomm(it.unich.jgmp.RandState,it.unich.jgmp.MPZ) instead, since this method uses a global random state and it is not reentrant.
      static MPZ random2​(long max_size)
      Deprecated.
      use rrandomb(it.unich.jgmp.RandState,long) instead, since this method uses a global random state and it is not reentrant.
      MPZ random2Assign​(long max_size)
      Deprecated.
      use rrandombAssign(it.unich.jgmp.RandState,long) instead, since this method uses a global random state and it is not reentrant.
      MPZ randomAssign​(long max_size)
      Deprecated.
      use urandombAssign(it.unich.jgmp.RandState,long) or urandommAssign(it.unich.jgmp.RandState,it.unich.jgmp.MPZ) instead, since this method uses a global random state and it is not reentrant.
      private void readObject​(java.io.ObjectInputStream in)  
      private void readObjectNoData()  
      MPZ realloc2​(long n)
      Changes the space allocated for this number to n bits.
      org.javatuples.Pair<java.lang.Long,​MPZ> remove​(MPZ f)
      Return the result of removing the factorf from this, together with the number of occurrences which were removed.
      long removeAssign​(MPZ f)
      Remove all occurrences of the factor f from this MPZ.
      long removeAssign​(MPZ op, MPZ f)
      Remove all occurrences of the factor f from op and stores the result in this MPZ.
      org.javatuples.Pair<java.lang.Boolean,​MPZ> root​(long n)
      Return an MPZ whose value is the truncated integer part of the nth root of this, and a boolean flag which is true when the result is exact.
      boolean rootAssign​(long n)
      Set this MPZ to the truncated integer part of its nth root.
      boolean rootAssign​(MPZ op, long n)
      Set this MPZ to the truncated integer part of the nth root of op.
      org.javatuples.Pair<MPZ,​MPZ> rootrem​(long n)
      Return two MPZs whose values are the truncated integer part of the nth root of this and the remainder, i.e., (u - rootn).
      MPZ rootremAssign​(MPZ rem, long n)
      Set this MPZ to the truncated integer part of the its nth root and rem to the remainder, i.e., (this - rootn).
      MPZ rootremAssign​(MPZ rem, MPZ u, long n)
      Set this MPZ to the truncated integer part of the nth root of u and rem to the remainder, i.e., (u - rootn).
      static MPZ rrandomb​(RandState s, long n)
      Return an MPZ whose value is a random integer with long strings of zeros and ones in the binary representation.
      MPZ rrandombAssign​(RandState s, long n)
      Set this MPZ to a random integer with long strings of zeros and ones in the binary representation.
      long scan0​(long starting_bit)
      Scan this MPZ, starting from bit starting_bit, towards more significant bits, until the first 0 bit is found.
      long scan1​(long starting_bit)
      Scan this, starting from bit starting_bit, towards more significant bits, until the first 1 bit is found.
      MPZ set​(double op)
      Set this MPZ to the truncation of op.
      MPZ set​(long op)
      Set this MPZ to op.
      MPZ set​(MPF op)
      Set this MPZ to the truncation of op.
      MPZ set​(MPQ op)
      Set this MPZ to the truncation of op.
      MPZ set​(MPZ op)
      Set this MPZ to op.
      (package private) static void set​(MpzT mpzNative, java.math.BigInteger op)  
      int set​(java.lang.String str, int base)
      Set this MPZ to the number represented by the string str in the specified base.
      MPZ set​(java.math.BigInteger op)
      Sets this MPZ to op.
      MPZ setbit​(long index)
      Return an MPZ whose value is (this | 2index).
      MPZ setbitAssign​(long index)
      Set the bit index of this MPZ.
      MPZ setUi​(long op)
      Set this MPZ to op.
      MPZ setValue​(double op)
      Set this MPZ to the truncation op op.
      MPZ setValue​(long op)
      Set this MPZ to signed long op.
      MPZ setValue​(MPF op)
      Set this MPZ to the truncation op op.
      MPZ setValue​(MPQ op)
      Set this MPZ to the truncation op op.
      MPZ setValue​(MPZ op)
      Set this MPZ to op.
      MPZ setValue​(java.lang.String str)
      Set this MPZ to the value represented by the string str in decimal base.
      MPZ setValue​(java.lang.String str, int base)
      Set this MPZ to the number represented by the string str in the specified base.
      MPZ setValue​(java.math.BigInteger op)
      Sets this MPZ to op.
      int sgn()
      Return +1 if (this > 0), 0 if (this = 0) and -1 if this < 0.
      long sizeinbase​(int base)
      Return the size of this MPZ measured in number of digits in the specified base.
      MPZ sqrt()
      Return an MPZ whose value is the truncated integer part of the square root of this.
      MPZ sqrtAssign()
      Set this MPZ to the truncated integer part of its square root.
      MPZ sqrtAssign​(MPZ op)
      Set this MPZ to the truncated integer part of the square root of op.
      org.javatuples.Pair<MPZ,​MPZ> sqrtrem()
      Return two MPZs whose values are the truncated integer part of the square root of this and the remainder, i.e., (op - root2).
      MPZ sqrtremAssign​(MPZ rem)
      Set this MPZ to the truncated integer part of its square root and rem to the remainder, i.e., (this - root2).
      MPZ sqrtremAssign​(MPZ rem, MPZ op)
      Set this MPZ to the truncated integer part of the square root of op and rem to the remainder, i.e., (op - root2).
      MPZ sub​(MPZ op)
      Return an MPZ whose value is (this - op).
      MPZ subAssign​(MPZ op)
      Set this MPZ to (this - op)
      MPZ subAssign​(MPZ op1, MPZ op2)
      Set this MPZ to (op1 - op2).
      MPZ submul​(MPZ op1, MPZ op2)
      Return an MPZ whose value is (this - op1 * op2).
      MPZ submulAssign​(MPZ op1, MPZ op2)
      Subtract (op1 * op2) to this MPZ.
      MPZ submulUi​(MPZ op1, long op2)
      Return an MPZ whose value is (this - op1 * op2).
      MPZ submulUiAssign​(MPZ op1, long op2)
      Subtract (op1 * op2) to this MPZ.
      MPZ subUi​(long op)
      Return an MPZ whose value is (this - op).
      MPZ subUiAssign​(long op)
      Set this MPZ to (this - op)
      MPZ subUiAssign​(MPZ op1, long op2)
      Set this MPZ to (op1 - op2).
      MPZ swap​(MPZ op)
      Swap the value of this MPZ with the value of op.
      MPZ tdivq​(MPZ d)
      Return an MPZ whose value is the quotient of the integer division (this / d), rounded towards zero.
      MPZ tdivq2Exp​(long b)
      Return an MPZ whose value is the quotient of the integer division (this / 2b), rounded towards zero.
      MPZ tdivq2ExpAssign​(long b)
      Set this MPZ to the quotient of the integer division (this / 2b), rounded toward zero.
      MPZ tdivq2ExpAssign​(MPZ n, long b)
      Set this MPZ to the quotient of the integer division (n / 2b), rounded toward zero.
      MPZ tdivqAssign​(MPZ d)
      Set this MPZ to the quotient of the integer division (this / d), rounded towards zero.
      MPZ tdivqAssign​(MPZ n, MPZ d)
      Set this MPZ to the quotient of the integer division (n / d), rounded towards zero.
      org.javatuples.Pair<MPZ,​MPZ> tdivqr​(MPZ d)
      Return two MPZs whose values are the quotient and remainder of the integer division (this / d), rounded towards zero.
      MPZ tdivqrAssign​(MPZ r, MPZ d)
      Set this MPZ and r to the quotient and remainder of the integer division (this / d), rounded towards zero.
      MPZ tdivqrAssign​(MPZ r, MPZ n, MPZ d)
      Set this MPZ and r to the quotient and remainder of the integer division (n / d), rounded towards zero.
      long tdivqrUiAssign​(MPZ r, long d)
      Set this MPZ and r 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 this MPZ and r 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 this MPZ 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 this MPZ to the quotient of the integer division (n / d), rounded towards zero; it also returns the absolute value of the remainder.
      MPZ tdivr​(MPZ d)
      Return an MPZ whose value is the remainder of the integer division (this / d), rounded towards zero.
      MPZ tdivr2Exp​(long b)
      Return an MPZ whose value is the remainder of the integer division (this / 2b), rounded towards zero.
      MPZ tdivr2ExpAssign​(long b)
      Set this MPZ to the remainder of the integer division (this / 2b), rounded toward zero.
      MPZ tdivr2ExpAssign​(MPZ n, long b)
      Set this MPZ to the remainder of the integer division (n / 2b), rounded toward zero.
      MPZ tdivrAssign​(MPZ d)
      Set this MPZ to the remainder of the integer division (this / d), rounded towards zero.
      MPZ tdivrAssign​(MPZ n, MPZ d)
      Set this MPZ to the remainder of the integer division (n / d), rounded towards zero.
      long tdivrUiAssign​(long d)
      Set this MPZ 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 this MPZ 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.
      java.lang.String toString()
      Convert this MPZ to its decimal string representation.
      java.lang.String toString​(int base)
      Convert this MPZ to its string representation in the specified base, or null if the base is not valid.
      int tstbit​(long index)
      Return the bit index of this MPZ.
      int uiKronecker​(long a)
      Return the Jacobi symbol (a / this) with the Kronecker extension.
      MPZ uiSub​(long op)
      Return an MPZ whose value is (op - this).
      MPZ uiSubAssign​(long op)
      Set this MPZ to (op - this)
      MPZ uiSubAssign​(long op1, MPZ op2)
      Set this MPZ to (op1 - op2).
      static MPZ urandomb​(RandState s, long n)
      Return an MPZ whose value is an uniformly distributed random integer in the range 0} to (2n - 1), inclusive.
      MPZ urandombAssign​(RandState s, long n)
      Set this MPZ to a uniformly distributed random integer in the range 0 to (2n - 1), inclusive.
      static MPZ urandomm​(RandState s, MPZ n)
      Return an MPZ whose value is an uniformly distributed random integer in the range 0 to (n - 1), inclusive.
      MPZ urandommAssign​(RandState s, MPZ n)
      Set this MPZ to a uniformly distributed random integer in the range 0 to (n - 1), inclusive.
      private void writeObject​(java.io.ObjectOutputStream out)  
      MPZ xor​(MPZ op)
      Return an MPZ whose value is (this ^ op).
      MPZ xorAssign​(MPZ op)
      Set this MPZ to (this ^ op).
      MPZ xorAssign​(MPZ op1, MPZ op2)
      Set this MPZ to (op1 ^ op2).
      • Methods inherited from class java.lang.Number

        byteValue, shortValue
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        Version for serializability.
        See Also:
        Constant Field Values
      • mpzNative

        private transient MpzT mpzNative
        The pointer to the native mpz_t object.
    • Constructor Detail

      • MPZ

        private MPZ​(MpzT pointer)
        A private constructor which build an MPZ starting from a pointer to its native data object. The native object needs to be already initialized.
      • MPZ

        public MPZ()
        Build an MPZ whose value is zero.
      • MPZ

        public MPZ​(MPZ op)
        Build an MPZ whose value is op.
      • MPZ

        public MPZ​(long op)
        Build an MPZ whose value is op.
      • MPZ

        public MPZ​(double op)
        Build an MPZ whose value is the truncation of op.
        Throws:
        java.lang.ArithmeticException - if op is not a finite number.
      • MPZ

        public MPZ​(MPQ op)
        Build an MPZ whose value is the truncation of op.
      • MPZ

        public MPZ​(MPF op)
        Build an MPZ whose value is the truncation of op.
      • MPZ

        public MPZ​(java.lang.String str,
                   int base)
        Build an MPZ whose value is the number represented by the string str in the specified base. See the GMP function mpz_init_set_str.
        Throws:
        java.lang.NumberFormatException - if either base is not valid or str is not a valid string in the specified base.
      • MPZ

        public MPZ​(java.lang.String str)
        Build an MPZ whose value is the number represented by the string str in decimal base. See the GMP function mpz_init_set_str.
        Throws:
        java.lang.NumberFormatException - if str is not a valid number representation in decimal base.
      • MPZ

        public MPZ​(java.math.BigInteger op)
        Builds an MPZ whose value is the same as op.
    • Method Detail

      • getNative

        public MpzT getNative()
        Return the native pointer to the GMP object.
      • init

        public static MPZ init()
        Return an MPZ whose value is zero.
      • init2

        public static MPZ init2​(long n)
        Return an MPZ whose value is zero, with pre-allocated space for n-bit numbers. Calling this method is never necessary; reallocation is handled automatically by GMP when needed. See the GMP function mpz_init2.
      • realloc2

        public MPZ realloc2​(long n)
        Changes the space allocated for this number to n 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

        public MPZ set​(MPZ op)
        Set this MPZ to op.
        Returns:
        this MPZ.
      • set

        public MPZ set​(long op)
        Set this MPZ to op.
        Returns:
        this MPZ.
      • setUi

        public MPZ setUi​(long op)
        Set this MPZ to op.
        Returns:
        this MPZ.
      • set

        public MPZ set​(double op)
        Set this MPZ to the truncation of op.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if op is not a finite number. In this case, this is not altered.
      • set

        public MPZ set​(MPQ op)
        Set this MPZ to the truncation of op.
        Returns:
        this MPZ.
      • set

        public MPZ set​(MPF op)
        Set this MPZ to the truncation of op.
        Returns:
        this MPZ.
      • set

        public int set​(java.lang.String str,
                       int base)
        Set this MPZ to the number represented by the string str in the specified base. See the GMP function mpz_set_str.
        Returns:
        0 if the operation succeeded, -1 otherwise. In the latter case, this is not altered.
      • set

        static void set​(MpzT mpzNative,
                        java.math.BigInteger op)
      • set

        public MPZ set​(java.math.BigInteger op)
        Sets this MPZ to op.
        Returns:
        this MPZ.
      • swap

        public MPZ swap​(MPZ op)
        Swap the value of this MPZ with the value of op.
        Returns:
        this MPZ.
      • initSet

        public static MPZ initSet​(MPZ op)
        Return an MPZ whose value is op.
      • initSet

        public static MPZ initSet​(long op)
        Return an MPZ whose value is op.
      • initSetUi

        public static MPZ initSetUi​(long op)
        Return an MPZ whose value is op.
      • initSet

        public static MPZ initSet​(double op)
        Return an MPZ whose value is the truncation of op.
        Throws:
        java.lang.ArithmeticException - if op is not a finite number.
      • initSet

        public static org.javatuples.Pair<java.lang.Integer,​MPZ> initSet​(java.lang.String str,
                                                                               int base)
        Return an MPZ whose value is the number represented by the string str in the specified base. See the GMP function mpz_init_set_str.
        Returns:
        a pair whose first component is 0 if the operation succeeded, and -1 if either base is not valid, or str is not a valid numeric representation in the specified base. The second component of the pair is the number represented in str if the operation succeeded, 0 otherwise.
      • getUi

        public long getUi()
        Convert this MPZ 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 this MPZ 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 this MPZ 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

        public org.javatuples.Pair<java.lang.Double,​java.lang.Long> getD2Exp()
        Convert this MPZ to a pair made of mantissa and exponent, truncating if necessary. See the GMP function mpz_get_d_2exp.
      • getStr

        public java.lang.String getStr​(int base)
        Return the String representation of this MPZ in the specified base, or null if the base is not valid. See the GMP function mpz_get_str.
      • getBigInteger

        public java.math.BigInteger getBigInteger()
        Converts this MPZ to BigInteger.
      • addAssign

        public MPZ addAssign​(MPZ op1,
                             MPZ op2)
        Set this MPZ to (op1 + op2).
        Returns:
        this MPZ.
      • addAssign

        public MPZ addAssign​(MPZ op)
        Set this MPZ to (this + op)
        Returns:
        this MPZ
      • add

        public MPZ add​(MPZ op)
        Return an MPZ whose value is (this + op).
      • addUiAssign

        public MPZ addUiAssign​(MPZ op1,
                               long op2)
        Set this MPZ to (op1 + op2).
        Returns:
        this MPZ.
      • addUiAssign

        public MPZ addUiAssign​(long op)
        Set this MPZ to (this + op)
        Returns:
        this MPZ
      • addUi

        public MPZ addUi​(long op)
        Return an MPZ whose value is (this + op).
      • subAssign

        public MPZ subAssign​(MPZ op1,
                             MPZ op2)
        Set this MPZ to (op1 - op2).
        Returns:
        this MPZ.
      • subAssign

        public MPZ subAssign​(MPZ op)
        Set this MPZ to (this - op)
        Returns:
        this MPZ
      • sub

        public MPZ sub​(MPZ op)
        Return an MPZ whose value is (this - op).
      • subUiAssign

        public MPZ subUiAssign​(MPZ op1,
                               long op2)
        Set this MPZ to (op1 - op2).
        Returns:
        this MPZ.
      • subUiAssign

        public MPZ subUiAssign​(long op)
        Set this MPZ to (this - op)
        Returns:
        this MPZ
      • subUi

        public MPZ subUi​(long op)
        Return an MPZ whose value is (this - op).
      • uiSubAssign

        public MPZ uiSubAssign​(long op1,
                               MPZ op2)
        Set this MPZ to (op1 - op2).
        Returns:
        this MPZ.
      • uiSubAssign

        public MPZ uiSubAssign​(long op)
        Set this MPZ to (op - this)
        Returns:
        this MPZ
      • uiSub

        public MPZ uiSub​(long op)
        Return an MPZ whose value is (op - this).
      • mulAssign

        public MPZ mulAssign​(MPZ op1,
                             MPZ op2)
        Set this MPZ to (op1 * op2).
        Returns:
        this MPZ.
      • mulAssign

        public MPZ mulAssign​(MPZ op)
        Set this MPZ to (this * op)
        Returns:
        this MPZ
      • mul

        public MPZ mul​(MPZ op)
        Return an MPZ whose value is (this * op).
      • mulUiAssign

        public MPZ mulUiAssign​(MPZ op1,
                               long op2)
        Set this MPZ to (op1 * op2).
        Returns:
        this MPZ.
      • mulUiAssign

        public MPZ mulUiAssign​(long op)
        Set this MPZ to (this * op)
        Returns:
        this MPZ
      • mulUi

        public MPZ mulUi​(long op)
        Return an MPZ whose value is (this * op).
      • mulAssign

        public MPZ mulAssign​(MPZ op1,
                             long op2)
        Set this MPZ to (op1 * op2).
        Returns:
        this MPZ.
      • mulAssign

        public MPZ mulAssign​(long op)
        Set this MPZ to (this * op)
        Returns:
        this MPZ
      • mul

        public MPZ mul​(long op)
        Return an MPZ whose value is (this * op).
      • addmulAssign

        public MPZ addmulAssign​(MPZ op1,
                                MPZ op2)
        Add (op1 * op2) to this MPZ.
        Returns:
        this MPZ.
      • addmul

        public MPZ addmul​(MPZ op1,
                          MPZ op2)
        Return an MPZ whose value is (this + op1 * op2).
      • addmulUiAssign

        public MPZ addmulUiAssign​(MPZ op1,
                                  long op2)
        Add (op1 * op2) to this MPZ.
        Returns:
        this MPZ.
      • addmulUi

        public MPZ addmulUi​(MPZ op1,
                            long op2)
        Return an MPZ whose value is (this + op1 * op2).
      • submulAssign

        public MPZ submulAssign​(MPZ op1,
                                MPZ op2)
        Subtract (op1 * op2) to this MPZ.
        Returns:
        this MPZ.
      • submul

        public MPZ submul​(MPZ op1,
                          MPZ op2)
        Return an MPZ whose value is (this - op1 * op2).
      • submulUiAssign

        public MPZ submulUiAssign​(MPZ op1,
                                  long op2)
        Subtract (op1 * op2) to this MPZ.
        Returns:
        this MPZ.
      • submulUi

        public MPZ submulUi​(MPZ op1,
                            long op2)
        Return an MPZ whose value is (this - op1 * op2).
      • mul2ExpAssign

        public MPZ mul2ExpAssign​(MPZ op,
                                 long b)
        Set this MPZ to (op * 2b).
        Returns:
        this MPZ.
      • mul2ExpAssign

        public MPZ mul2ExpAssign​(long b)
        Set this MPZ to (this * 2b).
        Returns:
        this MPZ.
      • mul2Exp

        public MPZ mul2Exp​(long b)
        Return an MPZ whose value is (this * 2b).
      • negAssign

        public MPZ negAssign​(MPZ op)
        Set this MPZ to (- op).
        Returns:
        this MPZ.
      • negAssign

        public MPZ negAssign()
        Set this MPZ to its opposite.
        Returns:
        this MPZ.
      • neg

        public MPZ neg()
        Return an MPZ whose value is the quotient of (- this).
      • absAssign

        public MPZ absAssign​(MPZ op)
        Set this MPZ to the absolute value of op.
        Returns:
        this MPZ.
      • absAssign

        public MPZ absAssign()
        Set this MPZ to its absolute value.
        Returns:
        this MPZ.
      • abs

        public MPZ abs()
        Return an MPZ whose value is the absolute value of this.
      • cdivqAssign

        public MPZ cdivqAssign​(MPZ n,
                               MPZ d)
        Set this MPZ to the quotient of the integer division (n / d), rounded towards +∞.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • cdivqAssign

        public MPZ cdivqAssign​(MPZ d)
        Set this MPZ to the quotient of the integer division (this / d), rounded towards +∞.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • cdivrAssign

        public MPZ cdivrAssign​(MPZ n,
                               MPZ d)
        Set this MPZ to the remainder of the integer division (n / d), rounded towards +∞.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • cdivrAssign

        public MPZ cdivrAssign​(MPZ d)
        Set this MPZ to the remainder of the integer division (this / d), rounded towards +∞.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • cdivqrAssign

        public MPZ cdivqrAssign​(MPZ r,
                                MPZ n,
                                MPZ d)
        Set this MPZ and r to the quotient and remainder of the integer division (n / d), rounded towards +∞.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
        java.lang.IllegalArgumentException - if this and r are the same object.
      • cdivqrAssign

        public MPZ cdivqrAssign​(MPZ r,
                                MPZ d)
        Set this MPZ and r to the quotient and remainder of the integer division (this / d), rounded towards +∞.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
        java.lang.IllegalArgumentException - if this and r are the same object.
      • cdivqUiAssign

        public long cdivqUiAssign​(MPZ n,
                                  long d)
        Set this MPZ to the quotient of the integer division (n / d), rounded towards +∞; it also Return the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • cdivqUiAssign

        public long cdivqUiAssign​(long d)
        Set this MPZ to the quotient of the integer division (this / d), rounded towards +∞; it also returns the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • cdivrUiAssign

        public long cdivrUiAssign​(MPZ n,
                                  long d)
        Set this MPZ to the remainder of the integer division (n / d), rounded towards +∞; it also returns the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • cdivrUiAssign

        public long cdivrUiAssign​(long d)
        Set this MPZ to the remainder of the integer division (this / d), rounded towards +∞; it also returns the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • cdivqrUiAssign

        public long cdivqrUiAssign​(MPZ r,
                                   MPZ n,
                                   long d)
        Set this MPZ and r to the quotient and remainder of the integer division (n / d), rounded towards +∞; it also returns the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
        java.lang.IllegalArgumentException - if this and r are the same object.
      • cdivqrUiAssign

        public long cdivqrUiAssign​(MPZ r,
                                   long d)
        Set this MPZ and r to the quotient and remainder of the integer division (this / d), rounded towards +∞; it also returns the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
        java.lang.IllegalArgumentException - if this and r are the same object.
      • cdivUi

        public long cdivUi​(long d)
        Return the remainder of the integer division (this / d), rounded towards +∞.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • cdivq2ExpAssign

        public MPZ cdivq2ExpAssign​(MPZ n,
                                   long b)
        Set this MPZ to the quotient of the integer division (n / 2b), rounded toward +∞.
        Returns:
        this MPZ.
      • cdivq2ExpAssign

        public MPZ cdivq2ExpAssign​(long b)
        Set this MPZ to the quotient of the integer division (this / 2b), rounded toward +∞.
        Returns:
        this MPZ.
      • cdivr2ExpAssign

        public MPZ cdivr2ExpAssign​(MPZ n,
                                   long b)
        Set this MPZ to the remainder of the integer division (n / 2b), rounded toward +∞.
        Returns:
        this MPZ.
      • cdivr2ExpAssign

        public MPZ cdivr2ExpAssign​(long b)
        Set this MPZ to the remainder of the integer division (this / 2b), rounded toward +∞.
        Returns:
        this MPZ.
      • cdivq

        public MPZ cdivq​(MPZ d)
        Return an MPZ whose value is the quotient of the integer division (this / d), rounded towards +∞.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • cdivr

        public MPZ cdivr​(MPZ d)
        Return an MPZ whose value is the remainder of the integer division (this / d), rounded towards +∞.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • cdivqr

        public org.javatuples.Pair<MPZ,​MPZ> cdivqr​(MPZ d)
        Return a pair of MPZs whose values are the quotient and remainder of the integer division (this / d), rounded towards +∞.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • cdivq2Exp

        public MPZ cdivq2Exp​(long b)
        Return an MPZ whose value is the quotient of the integer division (this / 2b), rounded towards +∞.
      • cdivr2Exp

        public MPZ cdivr2Exp​(long b)
        Return an MPZ whose value is the remainder of the integer division (this / 2b), rounded towards +∞.
      • fdivqAssign

        public MPZ fdivqAssign​(MPZ n,
                               MPZ d)
        Set this MPZ to the quotient of the integer division (n / d), rounded towards -∞.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • fdivqAssign

        public MPZ fdivqAssign​(MPZ d)
        Set this MPZ to the quotient of the integer division (this / d), rounded towards -∞.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • fdivrAssign

        public MPZ fdivrAssign​(MPZ n,
                               MPZ d)
        Set this MPZ to the remainder of the integer division (n / d), rounded towards -∞.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • fdivrAssign

        public MPZ fdivrAssign​(MPZ d)
        Set this MPZ to the remainder of the integer division (this / d), rounded towards -∞.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • fdivqrAssign

        public MPZ fdivqrAssign​(MPZ r,
                                MPZ n,
                                MPZ d)
        Set this MPZ and r to the quotient and remainder of the integer division (n / d), rounded towards -∞.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
        java.lang.IllegalArgumentException - if this and r are the same object.
      • fdivqrAssign

        public MPZ fdivqrAssign​(MPZ r,
                                MPZ d)
        Set this MPZ and r to the quotient and remainder of the integer division (this / d), rounded towards -∞.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
        java.lang.IllegalArgumentException - if this and r are the same object.
      • fdivqUiAssign

        public long fdivqUiAssign​(MPZ n,
                                  long d)
        Set this MPZ to the quotient of the integer division (n / d), rounded towards -∞; it also returns the absolute value of the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • fdivqUiAssign

        public long fdivqUiAssign​(long d)
        Set this MPZ to the quotient of the integer division (this / d), rounded towards -∞; it also returns the absolute value of the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • fdivrUiAssign

        public long fdivrUiAssign​(MPZ n,
                                  long d)
        Set this MPZ to the remainder of the integer division (n / d), rounded towards -∞; it also returns the absolute value of the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • fdivrUiAssign

        public long fdivrUiAssign​(long d)
        Set this MPZ to the remainder of the integer division (this / d), rounded towards -∞; it also returns the absolute value of the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • fdivqrUiAssign

        public long fdivqrUiAssign​(MPZ r,
                                   MPZ n,
                                   long d)
        Set this MPZ and r to the quotient and remainder of the integer division (n / d), rounded towards -∞; it also returns the absolute value of the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
        java.lang.IllegalArgumentException - if this and r are the same object.
      • fdivqrUiAssign

        public long fdivqrUiAssign​(MPZ r,
                                   long d)
        Set this MPZ and r to the quotient and remainder of the integer division (this / d), rounded towards -∞; it also returns the absolute value of the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
        java.lang.IllegalArgumentException - if this and r are the same object.
      • fdivUi

        public long fdivUi​(long d)
        Return the remainder of the integer division (this / d), rounded towards -∞.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • fdivq2ExpAssign

        public MPZ fdivq2ExpAssign​(MPZ n,
                                   long b)
        Set this MPZ to the quotient of the integer division (n / 2b), rounded toward -∞.
        Returns:
        this MPZ.
      • fdivq2ExpAssign

        public MPZ fdivq2ExpAssign​(long b)
        Set this MPZ to the quotient of the integer division (this / 2b), rounded toward -∞.
        Returns:
        this MPZ.
      • fdivr2ExpAssign

        public MPZ fdivr2ExpAssign​(MPZ n,
                                   long b)
        Set this MPZ to the remainder of the integer division (n / 2b), rounded toward -∞.
        Returns:
        this MPZ.
      • fdivr2ExpAssign

        public MPZ fdivr2ExpAssign​(long b)
        Set this MPZ to the remainder of the integer division (this / 2b), rounded toward -∞.
        Returns:
        this MPZ.
      • fdivq

        public MPZ fdivq​(MPZ d)
        Return an MPZ whose value is the quotient of the integer division (this / d), rounded towards -∞.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • fdivr

        public MPZ fdivr​(MPZ d)
        Return an MPZ whose value is the remainder of the integer division (this / d), rounded towards -∞.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • fdivqr

        public org.javatuples.Pair<MPZ,​MPZ> fdivqr​(MPZ d)
        Return two MPZs whose values are the quotient and remainder of the integer division (this / d), rounded towards -∞.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • fdivq2Exp

        public MPZ fdivq2Exp​(long b)
        Return an MPZ whose value is the quotient of the integer division (this / 2b), rounded towards -∞.
      • fdivr2Exp

        public MPZ fdivr2Exp​(long b)
        Return an MPZ whose value is the remainder of the integer division (this / 2b), rounded towards -∞.
      • tdivqAssign

        public MPZ tdivqAssign​(MPZ n,
                               MPZ d)
        Set this MPZ to the quotient of the integer division (n / d), rounded towards zero.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • tdivqAssign

        public MPZ tdivqAssign​(MPZ d)
        Set this MPZ to the quotient of the integer division (this / d), rounded towards zero.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • tdivrAssign

        public MPZ tdivrAssign​(MPZ n,
                               MPZ d)
        Set this MPZ to the remainder of the integer division (n / d), rounded towards zero.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • tdivrAssign

        public MPZ tdivrAssign​(MPZ d)
        Set this MPZ to the remainder of the integer division (this / d), rounded towards zero.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • tdivqrAssign

        public MPZ tdivqrAssign​(MPZ r,
                                MPZ n,
                                MPZ d)
        Set this MPZ and r to the quotient and remainder of the integer division (n / d), rounded towards zero.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
        java.lang.IllegalArgumentException - if this and r are the same object.
      • tdivqrAssign

        public MPZ tdivqrAssign​(MPZ r,
                                MPZ d)
        Set this MPZ and r to the quotient and remainder of the integer division (this / d), rounded towards zero.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
        java.lang.IllegalArgumentException - if this and r are the same object.
      • tdivqUiAssign

        public long tdivqUiAssign​(MPZ n,
                                  long d)
        Set this MPZ to the quotient of the integer division (n / d), rounded towards zero; it also returns the absolute value of the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • tdivqUiAssign

        public long tdivqUiAssign​(long d)
        Set this MPZ to the quotient of the integer division (this / d), rounded towards zero; it also returns the absolute value of the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • tdivrUiAssign

        public long tdivrUiAssign​(MPZ n,
                                  long d)
        Set this MPZ to the remainder of the integer division (n / d), rounded towards zero; it also returns the absolute value of the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • tdivrUiAssign

        public long tdivrUiAssign​(long d)
        Set this MPZ to the remainder of the integer division (this / d), rounded towards zero; it also returns the absolute value of the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • tdivqrUiAssign

        public long tdivqrUiAssign​(MPZ r,
                                   MPZ n,
                                   long d)
        Set this MPZ and r to the quotient and remainder of the integer division (n / d), rounded towards zero; it also returns the absolute value of the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
        java.lang.IllegalArgumentException - if this and r are the same object.
      • tdivqrUiAssign

        public long tdivqrUiAssign​(MPZ r,
                                   long d)
        Set this MPZ and r to the quotient and remainder of the integer division (this / d), rounded towards zero; it also returns the absolute value of the remainder.
        Throws:
        java.lang.ArithmeticException - if d is zero.
        java.lang.IllegalArgumentException - if this and r are the same object.
      • tdivUi

        public long tdivUi​(long d)
        Return the remainder of the integer division (this / d), rounded towards zero.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • tdivq2ExpAssign

        public MPZ tdivq2ExpAssign​(MPZ n,
                                   long b)
        Set this MPZ to the quotient of the integer division (n / 2b), rounded toward zero.
        Returns:
        this MPZ.
      • tdivq2ExpAssign

        public MPZ tdivq2ExpAssign​(long b)
        Set this MPZ to the quotient of the integer division (this / 2b), rounded toward zero.
        Returns:
        this MPZ.
      • tdivr2ExpAssign

        public MPZ tdivr2ExpAssign​(MPZ n,
                                   long b)
        Set this MPZ to the remainder of the integer division (n / 2b), rounded toward zero.
        Returns:
        this MPZ.
      • tdivr2ExpAssign

        public MPZ tdivr2ExpAssign​(long b)
        Set this MPZ to the remainder of the integer division (this / 2b), rounded toward zero.
        Returns:
        this MPZ.
      • tdivq

        public MPZ tdivq​(MPZ d)
        Return an MPZ whose value is the quotient of the integer division (this / d), rounded towards zero.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • tdivr

        public MPZ tdivr​(MPZ d)
        Return an MPZ whose value is the remainder of the integer division (this / d), rounded towards zero.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • tdivqr

        public org.javatuples.Pair<MPZ,​MPZ> tdivqr​(MPZ d)
        Return two MPZs whose values are the quotient and remainder of the integer division (this / d), rounded towards zero.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • tdivq2Exp

        public MPZ tdivq2Exp​(long b)
        Return an MPZ whose value is the quotient of the integer division (this / 2b), rounded towards zero.
      • tdivr2Exp

        public MPZ tdivr2Exp​(long b)
        Return an MPZ whose value is the remainder of the integer division (this / 2b), rounded towards zero.
      • modAssign

        public MPZ modAssign​(MPZ n,
                             MPZ d)
        Set this MPZ to (n mod d). The sign of the divisor is ignored, the result is always non-negative.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • modAssign

        public MPZ modAssign​(MPZ d)
        Set this MPZ to (this mod d). The sign of the divisor is ignored, the result is always non-negative.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • mod

        public MPZ mod​(MPZ d)
        Return an MPZ whose value is (this mod d). The sign of the divisor is ignored, the result is always non-negative.
      • modUiAssign

        public long modUiAssign​(MPZ n,
                                long d)
        Set this MPZ to (n mod d); it also returns the result. The sign of the divisor is ignored, the result is always non-negative.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • modUiAssign

        public long modUiAssign​(long d)
        Set this MPZ to (n mod d); it also returns the result. The sign of the divisor is ignored, the result is always non-negative.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • modUi

        public long modUi​(long d)
        Return an MPZ whose value is (this mod d). The sign of the divisor is ignored, the result is always non-negative.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • divexactAssign

        public MPZ divexactAssign​(MPZ n,
                                  MPZ d)
        Set this MPZ to the quotient of (n / d). This method produces correct results only when it is known in advance that d divides n.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • divexactAssign

        public MPZ divexactAssign​(MPZ d)
        Set this MPZ to the quotient of (this / d). This method produces correct results only when it is known in advance that d divides this.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • divexact

        public MPZ divexact​(MPZ d)
        Return an MPZ whose value is the quotient of (this / d). This method produces correct results only when it is known in advance that d divides this.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • divexactUiAssign

        public MPZ divexactUiAssign​(MPZ n,
                                    long d)
        Set this MPZ to the quotient of (n / d). This method produces correct results only when it is known in advance that d divides n.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • divexactUiAssign

        public MPZ divexactUiAssign​(long d)
        Set this MPZ to the quotient of (this / d). This method produces correct results only when it is known in advance that d divides this.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • divexactUi

        public MPZ divexactUi​(long d)
        Return an MPZ whose value is the quotient of (this / d). This method produces correct results only when it is known in advance that d divides this.
        Throws:
        java.lang.ArithmeticException - if d is zero.
      • isDivisible

        public boolean isDivisible​(MPZ d)
        Return true if and only if this is exactly divisible by d. This means that there exists an integer qsatisfying (n = q*d). Unlike the other division functions, the case d=0 is accepted and following the rule it can be seen that only 0 is considered divisible by 0.
      • isDivisibleUi

        public boolean isDivisibleUi​(long d)
        Return true if and only if this is exactly divisible by d. This means that there exists an integer q satisfying (n = q*d). The case d=0 is accepted and following the rule it can be seen that only 0 is considered divisible by 0.
      • isDivisible2Exp

        public boolean isDivisible2Exp​(long b)
        Return true if and only if this is exactly divisible by 2b. This means that there exists an integer q satisfying (n = q * 2^b).
      • isCongruent

        public boolean isCongruent​(MPZ c,
                                   MPZ d)
        Return true if and only if this is congruent to c modulo d. This means that there exists an integer q satisfying (n = c + q*d). Unlike the other division functions, d=0 is accepted and following the rule it can be seen that n and c are considered congruent modulo 0 only when exactly equal.
      • isCongruentUi

        public boolean isCongruentUi​(long c,
                                     long d)
        Return true if and only if this is congruent to c modulo d. This means that there exists an integer q satisfying (n = c + q*d). Unlike the other division functions, d=0 is accepted and following the rule it can be seen that n and c are considered congruent modulo 0 only when exactly equal.
      • isCongruent2Exp

        public boolean isCongruent2Exp​(MPZ c,
                                       long b)
        Return true if and only if this is congruent to c modulo 2b. This means that there exists an integer q satisfying (n = c + q*2^b).
      • powmAssign

        public MPZ powmAssign​(MPZ base,
                              MPZ exp,
                              MPZ mod)
        Set this MPZ to (baseexp) modulo mod. Negative exp is supported if the inverse of base modulo mod exists, otherwise an ArithmeticExpection is thrown.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if mod is zero or base has no inverse modulo mod.
      • powmAssign

        public MPZ powmAssign​(MPZ exp,
                              MPZ mod)
        Set this MPZ to (thisexp) modulo mod.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if mod is zero.
      • powm

        public MPZ powm​(MPZ exp,
                        MPZ mod)
        Return an MPZ whose value is (thisexp) modulo mod.
      • powmUiAssign

        public MPZ powmUiAssign​(MPZ base,
                                long exp,
                                MPZ mod)
        Set this MPZ to (baseexp) modulo mod.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if mod is zero.
      • powmUiAssign

        public MPZ powmUiAssign​(long exp,
                                MPZ mod)
        Set this MPZ to (thisexp) modulo mod.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if mod is zero.
      • powmUi

        public MPZ powmUi​(long exp,
                          MPZ mod)
        Return an MPZ whose value is (thisexp) modulo mod.
      • powmSecAssign

        public MPZ powmSecAssign​(MPZ base,
                                 MPZ exp,
                                 MPZ mod)
        Set this MPZ to (baseexp) modulo mod. It is required that (exp > 0 and that mod is odd. This function is intended for cryptographic purposes, where resilience to side-channel attacks is desired.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if mod is even or exp is negative.
      • powmSecAssign

        public MPZ powmSecAssign​(MPZ exp,
                                 MPZ mod)
        Set this MPZ to (thisexp) modulo mod. It is required that (exp > 0 and that mod is odd. This function is intended for cryptographic purposes, where resilience to side-channel attacks is desired.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if mod is zero.
      • powmSec

        public MPZ powmSec​(MPZ exp,
                           MPZ mod)
        Return an MPZ whose value is (thisexp) modulo mod. It is required that (exp > 0) and that mod is odd. This function is intended for cryptographic purposes, where resilience to side-channel attacks is desired.
      • powUiAssign

        public MPZ powUiAssign​(MPZ base,
                               long exp)
        Set this MPZ to (baseexp). The case 00 yields 1.
        Returns:
        this MPZ.
      • powUiAssign

        public MPZ powUiAssign​(long exp)
        Set this MPZ to (thisexp). The case 00 yields 1.
        Returns:
        this MPZ.
      • powUi

        public MPZ powUi​(long exp)
        Return an MPZ whose value is (thisexp). The case 00 yields 1.
      • powUiAssign

        public MPZ powUiAssign​(long base,
                               long exp)
        Set this MPZ to (baseexp). The case 00 yields 1.
        Returns:
        this MPZ.
      • powUi

        public static MPZ powUi​(long base,
                                long exp)
        Return an MPZ whose value is (baseexp). The case 00 yields 1.
      • rootAssign

        public boolean rootAssign​(MPZ op,
                                  long n)
        Set this MPZ to the truncated integer part of the nth root of op.
        Returns:
        true if the computation is exact.
        Throws:
        java.lang.ArithmeticException - if n is even and op is negative.
      • rootAssign

        public boolean rootAssign​(long n)
        Set this MPZ to the truncated integer part of its nth root.
        Returns:
        true if the computation is exact.
        Throws:
        java.lang.ArithmeticException - if n is even and this is negative.
      • root

        public org.javatuples.Pair<java.lang.Boolean,​MPZ> root​(long n)
        Return an MPZ whose value is the truncated integer part of the nth root of this, and a boolean flag which is true when the result is exact.
        Throws:
        java.lang.ArithmeticException - if n is even and this is negative.
      • rootremAssign

        public MPZ rootremAssign​(MPZ rem,
                                 MPZ u,
                                 long n)
        Set this MPZ to the truncated integer part of the nth root of u and rem to the remainder, i.e., (u - rootn).
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if n is even and u is negative.
      • rootremAssign

        public MPZ rootremAssign​(MPZ rem,
                                 long n)
        Set this MPZ to the truncated integer part of the its nth root and rem to the remainder, i.e., (this - rootn).
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if n is even and this is negative.
      • rootrem

        public org.javatuples.Pair<MPZ,​MPZ> rootrem​(long n)
        Return two MPZs whose values are the truncated integer part of the nth root of this and the remainder, i.e., (u - rootn).
        Throws:
        java.lang.ArithmeticException - if n is even and this is negative.
      • sqrtAssign

        public MPZ sqrtAssign​(MPZ op)
        Set this MPZ to the truncated integer part of the square root of op.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if op is negative.
      • sqrtAssign

        public MPZ sqrtAssign()
        Set this MPZ to the truncated integer part of its square root.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if this is negative.
      • sqrt

        public MPZ sqrt()
        Return an MPZ whose value is the truncated integer part of the square root of this.
        Throws:
        java.lang.ArithmeticException - if this is negative.
      • sqrtremAssign

        public MPZ sqrtremAssign​(MPZ rem,
                                 MPZ op)
        Set this MPZ to the truncated integer part of the square root of op and rem to the remainder, i.e., (op - root2).
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if op is negative.
      • sqrtremAssign

        public MPZ sqrtremAssign​(MPZ rem)
        Set this MPZ to the truncated integer part of its square root and rem to the remainder, i.e., (this - root2).
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if this is negative.
      • sqrtrem

        public org.javatuples.Pair<MPZ,​MPZ> sqrtrem()
        Return two MPZs whose values are the truncated integer part of the square root of this and the remainder, i.e., (op - root2).
        Throws:
        java.lang.ArithmeticException - if this is negative.
      • isPerfectPower

        public boolean isPerfectPower()
        Return true if and only if this number is a perfect power, i.e., if there exist integers a and b, with (b > 1), such that this equals (ab). Under this definition both 0 and 1 are considered to be perfect powers. Negative values are accepted, but of course can only be odd perfect powers.
      • isPerfectSquare

        public boolean isPerfectSquare()
        Return true if and only if this number is a perfect square. Under this definition both 0 and 1 are considered to be perfect squares.
      • isProbabPrime

        public MPZ.PrimalityStatus isProbabPrime​(int reps)
        Return true if and only if this is prime. See the GMP function mpz_probab_prime_p.
        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 whether this is definitely prime, probably prime or definitely non-prime.
      • nextprimeAssign

        public MPZ nextprimeAssign​(MPZ op)
        Set this MPZ to the next prime greater then op. 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

        public MPZ nextprimeAssign()
        Set this MPZ 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.
      • gcdAssign

        public MPZ gcdAssign​(MPZ op1,
                             MPZ op2)
        Set this MPZ to the greatest commond divisor of op1 and op2. The result is always positive even if one or both input operands are negative. Except if both inputs are zero; then this function defines gcd(0,0) = 0.
      • gcdAssign

        public MPZ gcdAssign​(MPZ op)
        Set this MPZ to the greatest commond divisor of this and op. The result is always positive even if one or both operands are negative. Except if both this and op are zero; then this function Return zero.
      • gcdUiAssign

        public long gcdUiAssign​(MPZ op1,
                                long op2)
        Set this MPZ to the greatest commond divisor of op1 and op2, and return it. If the result does not fit into an unsigned long, then 0 si returned.
        See Also:
        gcdAssign(it.unich.jgmp.MPZ,it.unich.jgmp.MPZ)
      • gcdUiAssign

        public long gcdUiAssign​(long op)
        Set this MPZ to the greatest commond divisor of op1 and op2, and returns it. If the result does not fit into an unsigned long, then 0 si returned.
        See Also:
        gcdAssign(it.unich.jgmp.MPZ,it.unich.jgmp.MPZ)
      • gcdUi

        public long gcdUi​(long op)
        Return the greatest commond divisor of this and op. If the result does not fit into an unsigned long, 0 is returned.
      • gcdextAssign

        public MPZ gcdextAssign​(MPZ s,
                                MPZ t,
                                MPZ a,
                                MPZ b)
        Set this MPZ to the greatest common divisor of a and b, and in addition Set s and t to coefficients satisfying (a*s + b*t = gcd). If s or t is null, that value is not computed. See the GMP function mpz_gcdext.
      • gcdextAssign

        public MPZ gcdextAssign​(MPZ s,
                                MPZ t,
                                MPZ op)
        Set this MPZ to the greatest common divisor of this and op, and in addition Set s and t to coefficients satisfying (this*s + op*t = gcd). If s or t is null, that value is not computed. See the GMP function mpz_gcdext.
      • gcdext

        public org.javatuples.Triplet<MPZ,​MPZ,​MPZ> gcdext​(MPZ op)
        Return the greatest common divisor of this and op, together with numbers s and t satisfying (a*this + b*op = g) See the GMP function mpz_gcdext.
      • lcmAssign

        public MPZ lcmAssign​(MPZ op1,
                             MPZ op2)
        Set this MPZ to the least common multiple of op1 and op2. The result is always non-negative even if one or both input operands are negative. The result will be zero if either op1 or op2 is zero.
      • lcmAssign

        public MPZ lcmAssign​(MPZ op)
        Set this MPZ to the least common multiple of this and op. The result is always non-negative even if one or both input operands are negative. The result will be zero if either this or op is zero.
      • invertAssign

        public boolean invertAssign​(MPZ op1,
                                    MPZ op2)
        Set this MPZ to the inverse of op1 modulo op2. If the inverse does not exist, the new value of this MPZ is undefined.
        Returns:
        true if the inverse exists, false otherwise.
      • invertAssign

        public boolean invertAssign​(MPZ op)
        Set this MPZ to the inverse of this modulo op. If the inverse does not exist, the new value of this MPZ is undefined.
        Returns:
        true if the inverse exists, false otherwise.
      • invert

        public java.util.Optional<MPZ> invert​(MPZ op)
        Optionally return, when it exists, an MPZ whose value is the inverse of this modulo op.
      • jacobi

        public int jacobi​(MPZ b)
        Return the Jacobi symbol (this / b). This is defined only for b odd.
      • legendre

        public int legendre​(MPZ p)
        Return the Legendre symbol (this / p). This is defined only for p an odd positive prime, and for such p it’s identical to the Jacobi symbol.
      • kronecker

        public int kronecker​(MPZ b)
        Return the Jacobi symbol (this / n) with the Kronecker extension (this/2)=(2/this) when this is odd, or (this/2)=0 when this is even. When b is odd the Jacobi symbol and Kronecker symbol are identical. See the GMP function mpz_kronecker.
      • kronecker

        public int kronecker​(long b)
        Return the Jacobi symbol (this / b) with the Kronecker extension.
        See Also:
        kronecker(it.unich.jgmp.MPZ)
      • kroneckerUi

        public int kroneckerUi​(long b)
        Return the Jacobi symbol (this / b) with the Kronecker extension.
        See Also:
        kronecker(it.unich.jgmp.MPZ)
      • kroneckerReverse

        public int kroneckerReverse​(long a)
        Return the Jacobi symbol (a / this) with the Kronecker extension.
        See Also:
        kronecker(it.unich.jgmp.MPZ)
      • uiKronecker

        public int uiKronecker​(long a)
        Return the Jacobi symbol (a / this) with the Kronecker extension.
        See Also:
        kronecker(it.unich.jgmp.MPZ)
      • removeAssign

        public long removeAssign​(MPZ op,
                                 MPZ f)
        Remove all occurrences of the factor f from op and stores the result in this MPZ. The return value is the number of occurrences of f which were removed.
      • removeAssign

        public long removeAssign​(MPZ f)
        Remove all occurrences of the factor f from this MPZ. The return value is the number of occurrences of f which were removed.
      • remove

        public org.javatuples.Pair<java.lang.Long,​MPZ> remove​(MPZ f)
        Return the result of removing the factorf from this, together with the number of occurrences which were removed.
      • facUiAssign

        public MPZ facUiAssign​(long n)
        Set this MPZ to the factorial of n.
      • facUi

        public static MPZ facUi​(long n)
        Return an MPZ whose value is the factorial of n.
      • dfacUiAssign

        public MPZ dfacUiAssign​(long n)
        Set this MPZ to the double factorial of n.
      • dfacUi

        public static MPZ dfacUi​(long n)
        Return an MPZ whose value the double factorial of n.
      • mfacUiUiAssign

        public MPZ mfacUiUiAssign​(long n,
                                  long m)
        Set this MPZ to the m-multi factorial of n.
      • mfacUiUi

        public static MPZ mfacUiUi​(long n,
                                   long m)
        Return an MPZ whose value is the m-multi factorial of n.
      • primorialUiAssign

        public MPZ primorialUiAssign​(long n)
        Set this MPZ to the primorial of n, i.e., the product of all positive prime numbers <= n.
      • primorialUi

        public static MPZ primorialUi​(long n)
        Return an MPZ whose value is the primorial of n, i.e., the product of all positive prime numbers <= n.
      • binUiAssign

        public MPZ binUiAssign​(MPZ n,
                               long k)
        Set this MPZ to the binomial coefficient n over k. Negative values of n 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

        public MPZ binUiAssign​(long k)
        Set this MPZ to the binomial coefficient this over k. Negative values of this 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.
      • binUiUiAssign

        public MPZ binUiUiAssign​(long n,
                                 long k)
        Set this MPZ to the binomial coefficient n over k.
      • binUiUi

        public static MPZ binUiUi​(long n,
                                  long k)
        Return an MPZ whose value is the binomial coefficient n over k.
      • fibUiAssign

        public MPZ fibUiAssign​(long n)
        Set this MPZ to the n-th Fibonacci number.
      • fibUi

        public static MPZ fibUi​(long n)
        Return an MPZ whose value is the n-th Fibonacci number.
      • fib2UiAssign

        public MPZ fib2UiAssign​(MPZ fnsub1,
                                long n)
        Set the value of this and fnsub1 to the n-th and (n-1)-th Fibonacci numbers respecively.
      • fib2Ui

        public static org.javatuples.Pair<MPZ,​MPZ> fib2Ui​(long n)
        Return two MPZ whose values are the n-th and (n-1)-th Fibonacci numbers.
      • lucnumUiAssign

        public MPZ lucnumUiAssign​(long n)
        Set this MPZ to the n-th Lucas number.
      • lucnumUi

        public static MPZ lucnumUi​(long n)
        Return an MPZ whose value is the n-th Lucas number.
      • lucnum2UiAssign

        public MPZ lucnum2UiAssign​(MPZ fnsub1,
                                   long n)
        Set the value of this and fnsub1 to the n-th and (n-1)-th Lucas numbers respecively.
      • lucnum2Ui

        public static org.javatuples.Pair<MPZ,​MPZ> lucnum2Ui​(long n)
        Return two MPZ whose values are the n-th and (n-1)-th Lucas numbers.
      • cmp

        public int cmp​(MPZ op)
        Compare this with op. Return a positive value if (this > op), zero if this = op, or a negative value if this < op.
      • cmp

        public int cmp​(double op)
        Compare this with op. Return a positive value if (this > op), zero if this = op, or a negative value if this < op. The value of op may be infinite, but the result is undefined on NaNs.
        Throws:
        java.lang.ArithmeticException - if op is a NaN.
      • cmp

        public int cmp​(long op)
        Compare this with op. Return a positive value if (this > op), zero if this = op, or a negative value if this < op.
      • cmpUi

        public int cmpUi​(long op)
        Compare this with op. Return a positive value if (this > op), zero if this = op, or a negative value if this < op.
      • cmpabs

        public int cmpabs​(MPZ op)
        Compare the absolute values of this and op. Return a positive value if (abs(this) > abs(op)), zero if abs(this) = abs(op), or a negative value if abs(this) < abs(op).
      • cmpabs

        public int cmpabs​(double op)
        Compare the absolute values of this and op. Return a positive value if (abs(this) > abs(op)), zero if abs(this) = abs(op), or a negative value if abs(this) < abs(op). The value of op may be infinite, but the result is undefined on NaNs.
        Throws:
        java.lang.ArithmeticException - if op is a NaN.
      • cmpabsUi

        public int cmpabsUi​(long op)
        Compare the absolute values of this and op. Return a positive value if (abs(this) > abs(op)), zero if abs(this) = abs(op), or a negative value if abs(this) < abs(op).
      • sgn

        public int sgn()
        Return +1 if (this > 0), 0 if (this = 0) and -1 if this < 0.
      • andAssign

        public MPZ andAssign​(MPZ op1,
                             MPZ op2)
        Set this MPZ to (op1 & op2).
      • andAssign

        public MPZ andAssign​(MPZ op)
        Set this MPZ to (this & op).
      • and

        public MPZ and​(MPZ op)
        Return an MPZ whose value is (this & op).
      • iorAssign

        public MPZ iorAssign​(MPZ op1,
                             MPZ op2)
        Set this MPZ to (op1 | op2).
      • iorAssign

        public MPZ iorAssign​(MPZ op)
        Set this MPZ to (this | op).
      • ior

        public MPZ ior​(MPZ op)
        Return an MPZ whose value is (this | op).
      • xorAssign

        public MPZ xorAssign​(MPZ op1,
                             MPZ op2)
        Set this MPZ to (op1 ^ op2).
      • xorAssign

        public MPZ xorAssign​(MPZ op)
        Set this MPZ to (this ^ op).
      • xor

        public MPZ xor​(MPZ op)
        Return an MPZ whose value is (this ^ op).
      • comAssign

        public MPZ comAssign​(MPZ op)
        Set this MPZ to (~ op).
      • comAssign

        public MPZ comAssign()
        Set this MPZ to (~ this).
      • com

        public MPZ com()
        Return an MPZ whose value is (~ op).
      • popcount

        public long popcount()
        If this MPZ is non-negative, return its population count, which is the number of 1 bits in its binary representation. If this MPZ is negative, the number of 1s is infinite, and the return value is the largest possible value for the native type mp_bitcnt_t.
      • hamdist

        public long hamdist​(MPZ op)
        If this and op are both >= 0 or both < 0, return the Hamming distance between them, which is the number of bit positions where this and op 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 type mp_bitcnt_t.
      • scan0

        public long scan0​(long starting_bit)
        Scan this MPZ, starting from bit starting_bit, towards more significant bits, until the first 0 bit is found. Return the index of the found bit.
      • scan1

        public long scan1​(long starting_bit)
        Scan this, starting from bit starting_bit, towards more significant bits, until the first 1 bit is found. Return the index of the found bit.
      • setbitAssign

        public MPZ setbitAssign​(long index)
        Set the bit index of this MPZ.
      • setbit

        public MPZ setbit​(long index)
        Return an MPZ whose value is (this | 2index).
      • clrbitAssign

        public MPZ clrbitAssign​(long index)
        Clear the bit index of this MPZ.
      • clrbit

        public MPZ clrbit​(long index)
        Return an MPZ whose value is (this & ~ 2index).
      • combitAssign

        public MPZ combitAssign​(long index)
        Complement the bit index of this MPZ.
      • combit

        public MPZ combit​(long index)
        Return an MPZ whose value is (this ^ 2index).
      • tstbit

        public int tstbit​(long index)
        Return the bit index of this MPZ.
      • urandombAssign

        public MPZ urandombAssign​(RandState s,
                                  long n)
        Set this MPZ to a uniformly distributed random integer in the range 0 to (2n - 1), inclusive.
      • urandomb

        public static MPZ urandomb​(RandState s,
                                   long n)
        Return an MPZ whose value is an uniformly distributed random integer in the range 0} to (2n - 1), inclusive.
      • urandommAssign

        public MPZ urandommAssign​(RandState s,
                                  MPZ n)
        Set this MPZ to a uniformly distributed random integer in the range 0 to (n - 1), inclusive.
      • urandomm

        public static MPZ urandomm​(RandState s,
                                   MPZ n)
        Return an MPZ whose value is an uniformly distributed random integer in the range 0 to (n - 1), inclusive.
      • rrandombAssign

        public MPZ rrandombAssign​(RandState s,
                                  long n)
        Set this MPZ 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

        public static MPZ rrandomb​(RandState s,
                                   long n)
        Return an MPZ 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.
      • random

        @Deprecated
        public static MPZ random​(long max_size)
        Deprecated.
        use urandomb(it.unich.jgmp.RandState,long) or urandomm(it.unich.jgmp.RandState,it.unich.jgmp.MPZ) instead, since this method uses a global random state and it is not reentrant.
        Return an MPZ whose value is a random integer of at most max_size limbs. The generated random number doesn’t satisfy any particular requirements of randomness. Negative random numbers are generated when max_size is negative.
      • random2Assign

        @Deprecated
        public MPZ random2Assign​(long max_size)
        Deprecated.
        use rrandombAssign(it.unich.jgmp.RandState,long) instead, since this method uses a global random state and it is not reentrant.
        Set this MPZ to a random integer of at most max_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 when max_size is negative.
        Returns:
        this MPZ.
      • random2

        @Deprecated
        public static MPZ random2​(long max_size)
        Deprecated.
        use rrandomb(it.unich.jgmp.RandState,long) instead, since this method uses a global random state and it is not reentrant.
        Return an MPZ whose value is a random integer of at most max_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 when max_size is negative.
      • bufferImportAssign

        public MPZ bufferImportAssign​(int order,
                                      int size,
                                      int endian,
                                      long nails,
                                      java.nio.ByteBuffer op)
        Set this MPZ from the buffer of word data at op. See the detailed description in the documentation of the GMP function mpz_import. The parameter count in the prototype of mpz_import is automatically computed by the capacity of the buffer op. The size parameter is declared as int instead of long since Java does not allow byte buffers to be longer than 4GB.
      • bufferImport

        public static MPZ bufferImport​(int order,
                                       int size,
                                       int endian,
                                       long nails,
                                       java.nio.ByteBuffer op)
        Return an MPZ whose value is determined from the buffer of word data at op. The size parameter is declared as int instead of long since Java does not allow byte buffers to be longer than 4GB.
        See Also:
        bufferImportAssign(int,int,int,long,java.nio.ByteBuffer)
      • bufferExport

        public java.nio.ByteBuffer bufferExport​(int order,
                                                int size,
                                                int endian,
                                                long nails)
        Return a ByteBuffer filled with word data from this MPZ. See the detailed description in the documentation of the GMP function mpz_export. We let the function allocate the buffer, since it the easier and safer. The output count of the original GMP function is not needed, since it corresponds to the capacity of the resulting ByteBuffer. The size parameter is declared as int instead of long since Java does not allow byte buffers to be longer than 4GB.
      • fitsUlong

        public boolean fitsUlong()
        Return true if and only if this MPZ fits into a native unsigned long.
      • fitsSlong

        public boolean fitsSlong()
        Return true if and only if this MPZ fits into a native signed long.
      • fitsUint

        public boolean fitsUint()
        Return true if and only if this MPZ fits into a native unsigned int.
      • fitsSint

        public boolean fitsSint()
        Return true if and only if this MPZ fits into a native signed int.
      • fitsUshort

        public boolean fitsUshort()
        Return true if and only if this MPZ fits into a native unsigned short.
      • fitsSshort

        public boolean fitsSshort()
        Return true if and only if this MPZ fits into a native signed short.
      • isOdd

        public boolean isOdd()
        Return true if and only if this MPZ is odd.
      • isEven

        public boolean isEven()
        Return true if and only if this MPZ is even
      • isZero

        public boolean isZero()
        Return true if and only if this MPZ is zero.
      • sizeinbase

        public long sizeinbase​(int base)
        Return the size of this MPZ measured in number of digits in the specified base. See the the GMP function mpz_sizeinbase.
        Throws:
        java.lang.IllegalArgumentException - if base is not between 2 and 62.
      • setValue

        public MPZ setValue​(MPZ op)
        Set this MPZ to op.
        Returns:
        this MPZ.
      • setValue

        public MPZ setValue​(long op)
        Set this MPZ to signed long op.
        Returns:
        this MPZ.
      • setValue

        public MPZ setValue​(double op)
        Set this MPZ to the truncation op op.
        Returns:
        this MPZ.
        Throws:
        java.lang.ArithmeticException - if op is not a finite number. In this case, this is not altered.
      • setValue

        public MPZ setValue​(MPQ op)
        Set this MPZ to the truncation op op.
        Returns:
        this MPZ.
      • setValue

        public MPZ setValue​(MPF op)
        Set this MPZ to the truncation op op.
        Returns:
        this MPZ.
      • setValue

        public MPZ setValue​(java.lang.String str,
                            int base)
        Set this MPZ to the number represented by the string str in the specified base. See the GMP function mpz_set_str.
        Throws:
        java.lang.NumberFormatException - if either base is not valid or str is not a valid number representation in the specified base. In this case, this is not altered.
      • setValue

        public MPZ setValue​(java.lang.String str)
        Set this MPZ to the value represented by the string str in decimal base.
        Throws:
        java.lang.NumberFormatException - if str is not a valid number representation in decimal base.
        See Also:
        setValue(java.lang.String,int)
      • setValue

        public MPZ setValue​(java.math.BigInteger op)
        Sets this MPZ to op.
        Returns:
        this MPZ.
      • compareTo

        public int compareTo​(MPZ op)
        Compare this MPZ with op. Return a positive value if (this > op), zero if this = op, or a negative value if this < op. This order is compatible with equality.
        Specified by:
        compareTo in interface java.lang.Comparable<MPZ>
      • equals

        public boolean equals​(java.lang.Object obj)
        Compare this MPZ with the object op for equality. It returns true if and only if op is an MPZ with the same value of this.
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Return a hash code value for this MPZ.
        Overrides:
        hashCode in class java.lang.Object
      • longValue

        public long longValue()
        Convert this MPZ to a signed long. If this number is too big to fit a native signed long, return the least significant part, preserving the sign.
        Specified by:
        longValue in class java.lang.Number
      • intValue

        public int intValue()
        Convert this MPZ to a signed int, truncating if necessary.
        Specified by:
        intValue in class java.lang.Number
      • doubleValue

        public double doubleValue()
        Convert this MPZ 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 class java.lang.Number
      • floatValue

        public float floatValue()
        Convert this MPZ to a float, truncating if necessary.
        Specified by:
        floatValue in class java.lang.Number
      • toString

        public java.lang.String toString​(int base)
        Convert this MPZ to its string representation in the specified base, or null if the base is not valid. See the GMP function mpz_get_str.
      • toString

        public java.lang.String toString()
        Convert this MPZ to its decimal string representation.
        Overrides:
        toString in class java.lang.Object
      • writeObject

        private void writeObject​(java.io.ObjectOutputStream out)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • readObject

        private void readObject​(java.io.ObjectInputStream in)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • readObjectNoData

        private void readObjectNoData()
                               throws java.io.ObjectStreamException
        Throws:
        java.io.ObjectStreamException