Package it.unich.jgmp

Class MPZ

All Implemented Interfaces:
Serializable, Comparable<MPZ>

public class MPZ extends Number implements Comparable<MPZ>
Multi-precision integer number. This class encapsulates the mpz_t data type, see the Integer Functions page of the GMP manual. In determining the names and prototypes of the methods of the MPZ class, we adopt the rules described in the documentation of the it.unich.jgmp package, enriched with the following ones:
  • the functions in the categories I/O of Integers, Integer Import and Export and Special Functions are not exposed by the MPZ class.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
    Cleaning action for the MPZ class.
    static enum 
    Result enumeration for the isProbabPrime(int) method.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private MpzT
    The pointer to the native mpz_t object.
    private static final long
    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(String str)
    Build an MPZ whose value is the number represented by the string str in decimal base.
     
    MPZ(String str, int base)
    Build an MPZ whose value is the number represented by the string str in the specified base.
     
    Builds an MPZ whose value is the same as op.
  • Method Summary

    Modifier and Type
    Method
    Description
    abs()
    Return an MPZ whose value is the absolute value of this.
    Set this MPZ to its absolute value.
    Set this MPZ to the absolute value of op.
    add(MPZ op)
    Return an MPZ whose value is (this + op).
    Set this MPZ to (this + op)
    addAssign(MPZ op1, MPZ op2)
    Set this MPZ to (op1 + op2).
    addmul(MPZ op1, MPZ op2)
    Return an MPZ whose value is (this + op1 * op2).
    addmulAssign(MPZ op1, MPZ op2)
    Add (op1 * op2) to this MPZ.
    addmulUi(MPZ op1, long op2)
    Return an MPZ whose value is (this + op1 * op2).
    addmulUiAssign(MPZ op1, long op2)
    Add (op1 * op2) to this MPZ.
    addUi(long op)
    Return an MPZ whose value is (this + op).
    addUiAssign(long op)
    Set this MPZ to (this + op)
    addUiAssign(MPZ op1, long op2)
    Set this MPZ to (op1 + op2).
    and(MPZ op)
    Return an MPZ whose value is (this & op).
    Set this MPZ to (this & op).
    andAssign(MPZ op1, MPZ op2)
    Set this MPZ to (op1 & op2).
    binUi(long k)
    Return an MPZ whose value is the binomial coefficient this over k.
    binUiAssign(long k)
    Set this MPZ to the binomial coefficient this over k.
    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.
    binUiUiAssign(long n, long k)
    Set this MPZ to the binomial coefficient n over k.
    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, ByteBuffer op)
    Return an MPZ whose value is determined from the buffer of word data at op.
    bufferImportAssign(int order, int size, int endian, long nails, ByteBuffer op)
    Set this MPZ from the buffer of word data at op.
    Return an MPZ whose value is the quotient of the integer division (this / d), rounded towards +∞.
    cdivq2Exp(long b)
    Return an MPZ whose value is the quotient of the integer division (this / 2b), rounded towards +∞.
    Set this MPZ to the quotient of the integer division (this / 2b), rounded toward +∞.
    cdivq2ExpAssign(MPZ n, long b)
    Set this MPZ to the quotient of the integer division (n / 2b), rounded toward +∞.
    Set this MPZ to the quotient of the integer division (this / d), rounded towards +∞.
    Set this MPZ to the quotient of the integer division (n / d), rounded towards +∞.
    org.javatuples.Pair<MPZ,MPZ>
    Return a pair of MPZs whose values are the quotient and remainder of the integer division (this / d), rounded towards +∞.
    Set this MPZ and r to the quotient and remainder of the integer division (this / d), rounded towards +∞.
    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.
    Return an MPZ whose value is the remainder of the integer division (this / d), rounded towards +∞.
    cdivr2Exp(long b)
    Return an MPZ whose value is the remainder of the integer division (this / 2b), rounded towards +∞.
    Set this MPZ to the remainder of the integer division (this / 2b), rounded toward +∞.
    cdivr2ExpAssign(MPZ n, long b)
    Set this MPZ to the remainder of the integer division (n / 2b), rounded toward +∞.
    Set this MPZ to the remainder of the integer division (this / d), rounded towards +∞.
    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 +∞.
    clrbit(long index)
    Return an MPZ whose value is (this & ~ 2index).
    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.
    com()
    Return an MPZ whose value is (~ op).
    Set this MPZ to (~ this).
    Set this MPZ to (~ op).
    combit(long index)
    Return an MPZ whose value is (this ^ 2index).
    combitAssign(long index)
    Complement the bit index of this MPZ.
    int
    Compare this MPZ with op.
    static MPZ
    dfacUi(long n)
    Return an MPZ whose value the double factorial of n.
    dfacUiAssign(long n)
    Set this MPZ to the double factorial of n.
    Return an MPZ whose value is the quotient of (this / d).
    Set this MPZ to the quotient of (this / d).
    Set this MPZ to the quotient of (n / d).
    divexactUi(long d)
    Return an MPZ whose value is the quotient of (this / d).
    Set this MPZ to the quotient of (this / d).
    divexactUiAssign(MPZ n, long d)
    Set this MPZ to the quotient of (n / d).
    double
    Convert this MPZ to a double, truncating if necessary.
    boolean
    Compare this MPZ with the object op for equality.
    static MPZ
    facUi(long n)
    Return an MPZ whose value is the factorial of n.
    facUiAssign(long n)
    Set this MPZ to the factorial of n.
    Return an MPZ whose value is the quotient of the integer division (this / d), rounded towards -∞.
    fdivq2Exp(long b)
    Return an MPZ whose value is the quotient of the integer division (this / 2b), rounded towards -∞.
    Set this MPZ to the quotient of the integer division (this / 2b), rounded toward -∞.
    fdivq2ExpAssign(MPZ n, long b)
    Set this MPZ to the quotient of the integer division (n / 2b), rounded toward -∞.
    Set this MPZ to the quotient of the integer division (this / d), rounded towards -∞.
    Set this MPZ to the quotient of the integer division (n / d), rounded towards -∞.
    org.javatuples.Pair<MPZ,MPZ>
    Return two MPZs whose values are the quotient and remainder of the integer division (this / d), rounded towards -∞.
    Set this MPZ and r to the quotient and remainder of the integer division (this / d), rounded towards -∞.
    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.
    Return an MPZ whose value is the remainder of the integer division (this / d), rounded towards -∞.
    fdivr2Exp(long b)
    Return an MPZ whose value is the remainder of the integer division (this / 2b), rounded towards -∞.
    Set this MPZ to the remainder of the integer division (this / 2b), rounded toward -∞.
    fdivr2ExpAssign(MPZ n, long b)
    Set this MPZ to the remainder of the integer division (n / 2b), rounded toward -∞.
    Set this MPZ to the remainder of the integer division (this / d), rounded towards -∞.
    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.
    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.
    fibUiAssign(long n)
    Set this MPZ to the n-th Fibonacci number.
    boolean
    Return true if and only if this MPZ fits into a native signed int.
    boolean
    Return true if and only if this MPZ fits into a native signed long.
    boolean
    Return true if and only if this MPZ fits into a native signed short.
    boolean
    Return true if and only if this MPZ fits into a native unsigned int.
    boolean
    Return true if and only if this MPZ fits into a native unsigned long.
    boolean
    Return true if and only if this MPZ fits into a native unsigned short.
    float
    Convert this MPZ to a float, truncating if necessary.
    gcd(MPZ op)
    Return an MPZ whose value is the greatest commond divisor of this and op.
    Set this MPZ to the greatest commond divisor of this and op.
    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.
    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).
    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.
    Converts this MPZ to BigInteger.
    double
    Convert this MPZ to a double, truncating if necessary.
    org.javatuples.Pair<Double,Long>
    Convert this MPZ to a pair made of mantissa and exponent, truncating if necessary.
    Return the native pointer to the GMP object.
    long
    Convert this MPZ to a signed long.
    getStr(int base)
    Return the String representation of this MPZ in the specified base, or null if the base is not valid.
    long
    Convert this MPZ to an unsigned long.
    long
    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
    Return a hash code value for this MPZ.
    static MPZ
    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
    Return an MPZ whose value is op.
    static org.javatuples.Pair<Integer,MPZ>
    initSet(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
    Convert this MPZ to a signed int, truncating if necessary.
    invert(MPZ op)
    Optionally return, when it exists, an MPZ whose value is the inverse of this modulo op.
    boolean
    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.
    ior(MPZ op)
    Return an MPZ whose value is (this | op).
    Set this MPZ to (this | op).
    iorAssign(MPZ op1, MPZ op2)
    Set this MPZ to (op1 | op2).
    boolean
    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
    Return true if and only if this is exactly divisible by d.
    boolean
    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
    Return true if and only if this MPZ is even
    boolean
    Return true if and only if this MPZ is odd.
    boolean
    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
    Return true if and only if this number is a perfect square.
    isProbabPrime(int reps)
    Return true if and only if this is prime.
    boolean
    Return true if and only if this MPZ is zero.
    int
    Return the Jacobi symbol (this / b).
    int
    kronecker(long b)
    Return the Jacobi symbol (this / b) with the Kronecker extension.
    int
    Return the Jacobi symbol (this / n) with the Kronecker extension (this/2)=(2/this) when this is odd, or (this/2)=0 when this is even.
    int
    Return the Jacobi symbol (a / this) with the Kronecker extension.
    int
    kroneckerUi(long b)
    Return the Jacobi symbol (this / b) with the Kronecker extension.
    lcm(MPZ op)
    Return an MPZ whose value is the least common multiple of this and op.
    Set this MPZ to the least common multiple of this and op.
    lcmAssign(MPZ op1, MPZ op2)
    Set this MPZ to the least common multiple of op1 and op2.
    lcmUi(long op)
    Return the least common multiple of this and op.
    lcmUiAssign(long op)
    Set this MPZ to the least common multiple of this and op.
    lcmUiAssign(MPZ op1, long op2)
    Set this MPZ to the least common multiple of op1 and op2.
    int
    Return the Legendre symbol (this / p).
    long
    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.
    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.
    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.
    mfacUiUiAssign(long n, long m)
    Set this MPZ to the m-multi factorial of n.
    mod(MPZ d)
    Return an MPZ whose value is (this mod d).
    Set this MPZ to (this mod d).
    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.
    mul(long op)
    Return an MPZ whose value is (this * op).
    mul(MPZ op)
    Return an MPZ whose value is (this * op).
    mul2Exp(long b)
    Return an MPZ whose value is (this * 2b).
    mul2ExpAssign(long b)
    Set this MPZ to (this * 2b).
    mul2ExpAssign(MPZ op, long b)
    Set this MPZ to (op * 2b).
    mulAssign(long op)
    Set this MPZ to (this * op)
    Set this MPZ to (this * op)
    mulAssign(MPZ op1, long op2)
    Set this MPZ to (op1 * op2).
    mulAssign(MPZ op1, MPZ op2)
    Set this MPZ to (op1 * op2).
    mulUi(long op)
    Return an MPZ whose value is (this * op).
    mulUiAssign(long op)
    Set this MPZ to (this * op)
    mulUiAssign(MPZ op1, long op2)
    Set this MPZ to (op1 * op2).
    neg()
    Return an MPZ whose value is the quotient of (- this).
    Set this MPZ to its opposite.
    Set this MPZ to (- op).
    Return an MPZ whose value is the next prime greater then this.
    Set this MPZ to the next prime greater then itself.
    Set this MPZ to the next prime greater then op.
    long
    If this MPZ is non-negative, return its population count, which is the number of 1 bits in its binary representation.
    powm(MPZ exp, MPZ mod)
    Return an MPZ whose value is (thisexp) modulo mod.
    powmAssign(MPZ exp, MPZ mod)
    Set this MPZ to (thisexp) modulo mod.
    powmAssign(MPZ base, MPZ exp, MPZ mod)
    Set this MPZ to (baseexp) modulo mod.
    powmSec(MPZ exp, MPZ mod)
    Return an MPZ whose value is (thisexp) modulo mod.
    powmSecAssign(MPZ exp, MPZ mod)
    Set this MPZ to (thisexp) modulo mod.
    powmSecAssign(MPZ base, MPZ exp, MPZ mod)
    Set this MPZ to (baseexp) modulo mod.
    powmUi(long exp, MPZ mod)
    Return an MPZ whose value is (thisexp) modulo mod.
    powmUiAssign(long exp, MPZ mod)
    Set this MPZ to (thisexp) modulo mod.
    powmUiAssign(MPZ base, long exp, MPZ mod)
    Set this MPZ to (baseexp) modulo mod.
    powUi(long exp)
    Return an MPZ whose value is (thisexp).
    static MPZ
    powUi(long base, long exp)
    Return an MPZ whose value is (baseexp).
    powUiAssign(long exp)
    Set this MPZ to (thisexp).
    powUiAssign(long base, long exp)
    Set this MPZ to (baseexp).
    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.
    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.
    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.
    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
     
    private void
     
    realloc2(long n)
    Changes the space allocated for this number to n bits.
    org.javatuples.Pair<Long,MPZ>
    Return the result of removing the factorf from this, together with the number of occurrences which were removed.
    long
    Remove all occurrences of the factor f from this MPZ.
    long
    Remove all occurrences of the factor f from op and stores the result in this MPZ.
    org.javatuples.Pair<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).
    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).
    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.
    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.
    set(double op)
    Set this MPZ to the truncation of op.
    set(long op)
    Set this MPZ to op.
    set(MPF op)
    Set this MPZ to the truncation of op.
    set(MPQ op)
    Set this MPZ to the truncation of op.
    set(MPZ op)
    Set this MPZ to op.
    (package private) static void
    set(MpzT mpzNative, BigInteger op)
     
    int
    set(String str, int base)
    Set this MPZ to the number represented by the string str in the specified base.
    Sets this MPZ to op.
    setbit(long index)
    Return an MPZ whose value is (this | 2index).
    setbitAssign(long index)
    Set the bit index of this MPZ.
    setUi(long op)
    Set this MPZ to op.
    setValue(double op)
    Set this MPZ to the truncation op op.
    setValue(long op)
    Set this MPZ to signed long op.
    Set this MPZ to the truncation op op.
    Set this MPZ to the truncation op op.
    Set this MPZ to op.
    Set this MPZ to the value represented by the string str in decimal base.
    setValue(String str, int base)
    Set this MPZ to the number represented by the string str in the specified base.
    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.
    Return an MPZ whose value is the truncated integer part of the square root of this.
    Set this MPZ to the truncated integer part of its square root.
    Set this MPZ to the truncated integer part of the square root of op.
    org.javatuples.Pair<MPZ,MPZ>
    Return two MPZs whose values are the truncated integer part of the square root of this and the remainder, i.e., (op - root2).
    Set this MPZ to the truncated integer part of its square root and rem to the remainder, i.e., (this - root2).
    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).
    sub(MPZ op)
    Return an MPZ whose value is (this - op).
    Set this MPZ to (this - op)
    subAssign(MPZ op1, MPZ op2)
    Set this MPZ to (op1 - op2).
    submul(MPZ op1, MPZ op2)
    Return an MPZ whose value is (this - op1 * op2).
    submulAssign(MPZ op1, MPZ op2)
    Subtract (op1 * op2) to this MPZ.
    submulUi(MPZ op1, long op2)
    Return an MPZ whose value is (this - op1 * op2).
    submulUiAssign(MPZ op1, long op2)
    Subtract (op1 * op2) to this MPZ.
    subUi(long op)
    Return an MPZ whose value is (this - op).
    subUiAssign(long op)
    Set this MPZ to (this - op)
    subUiAssign(MPZ op1, long op2)
    Set this MPZ to (op1 - op2).
    swap(MPZ op)
    Swap the value of this MPZ with the value of op.
    Return an MPZ whose value is the quotient of the integer division (this / d), rounded towards zero.
    tdivq2Exp(long b)
    Return an MPZ whose value is the quotient of the integer division (this / 2b), rounded towards zero.
    Set this MPZ to the quotient of the integer division (this / 2b), rounded toward zero.
    tdivq2ExpAssign(MPZ n, long b)
    Set this MPZ to the quotient of the integer division (n / 2b), rounded toward zero.
    Set this MPZ to the quotient of the integer division (this / d), rounded towards zero.
    Set this MPZ to the quotient of the integer division (n / d), rounded towards zero.
    org.javatuples.Pair<MPZ,MPZ>
    Return two MPZs whose values are the quotient and remainder of the integer division (this / d), rounded towards zero.
    Set this MPZ and r to the quotient and remainder of the integer division (this / d), rounded towards zero.
    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.
    Return an MPZ whose value is the remainder of the integer division (this / d), rounded towards zero.
    tdivr2Exp(long b)
    Return an MPZ whose value is the remainder of the integer division (this / 2b), rounded towards zero.
    Set this MPZ to the remainder of the integer division (this / 2b), rounded toward zero.
    tdivr2ExpAssign(MPZ n, long b)
    Set this MPZ to the remainder of the integer division (n / 2b), rounded toward zero.
    Set this MPZ to the remainder of the integer division (this / d), rounded towards zero.
    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.
    Convert this MPZ to its decimal string representation.
    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.
    uiSub(long op)
    Return an MPZ whose value is (op - this).
    uiSubAssign(long op)
    Set this MPZ to (op - this)
    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.
    Set this MPZ to a uniformly distributed random integer in the range 0 to (2n - 1), inclusive.
    static MPZ
    Return an MPZ whose value is an uniformly distributed random integer in the range 0 to (n - 1), inclusive.
    Set this MPZ to a uniformly distributed random integer in the range 0 to (n - 1), inclusive.
    private void
     
    xor(MPZ op)
    Return an MPZ whose value is (this ^ op).
    Set this MPZ to (this ^ op).
    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 Details

    • serialVersionUID

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

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

    • 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:
      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(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:
      NumberFormatException - if either base is not valid or str is not a valid string in the specified base.
    • MPZ

      public MPZ(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:
      NumberFormatException - if str is not a valid number representation in decimal base.
    • MPZ

      public MPZ(BigInteger op)
      Builds an MPZ whose value is the same as op.
  • Method Details

    • 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:
      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(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, BigInteger op)
    • set

      public MPZ set(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:
      ArithmeticException - if op is not a finite number.
    • initSet

      public static org.javatuples.Pair<Integer,MPZ> initSet(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<Double,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 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 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:
      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:
      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:
      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:
      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:
      ArithmeticException - if d is zero.
      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:
      ArithmeticException - if d is zero.
      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:
      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:
      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:
      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:
      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:
      ArithmeticException - if d is zero.
      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:
      ArithmeticException - if d is zero.
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      ArithmeticException - if d is zero.
      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:
      ArithmeticException - if d is zero.
      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:
      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:
      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:
      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:
      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:
      ArithmeticException - if d is zero.
      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:
      ArithmeticException - if d is zero.
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      ArithmeticException - if d is zero.
      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:
      ArithmeticException - if d is zero.
      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:
      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:
      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:
      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:
      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:
      ArithmeticException - if d is zero.
      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:
      ArithmeticException - if d is zero.
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      ArithmeticException - if mod is zero.
    • powmUiAssign

      public MPZ powmUiAssign(long exp, MPZ mod)
      Set this MPZ to (thisexp) modulo mod.
      Returns:
      this MPZ.
      Throws:
      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:
      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:
      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:
      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:
      ArithmeticException - if n is even and this is negative.
    • root

      public org.javatuples.Pair<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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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:
      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.
    • nextprime

      public MPZ nextprime()
      Return an MPZ whose value is the next prime greater then this.
      See Also:
    • 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.
    • gcd

      public MPZ gcd(MPZ op)
      Return an MPZ whose value is the greatest commond divisor of this and op.
      See Also:
    • 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:
    • 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:
    • 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.
    • lcm

      public MPZ lcm(MPZ op)
      Return an MPZ whose value is the least common multiple of this and op.
      See Also:
    • lcmUiAssign

      public MPZ lcmUiAssign(MPZ op1, long op2)
      Set this MPZ to the least common multiple of op1 and op2.
      See Also:
    • lcmUiAssign

      public MPZ lcmUiAssign(long op)
      Set this MPZ to the least common multiple of this and op.
      See Also:
    • lcmUi

      public MPZ lcmUi(long op)
      Return the least common multiple of this and op.
      See Also:
    • 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 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:
    • kroneckerUi

      public int kroneckerUi(long b)
      Return the Jacobi symbol (this / b) with the Kronecker extension.
      See Also:
    • kroneckerReverse

      public int kroneckerReverse(long a)
      Return the Jacobi symbol (a / this) with the Kronecker extension.
      See Also:
    • uiKronecker

      public int uiKronecker(long a)
      Return the Jacobi symbol (a / this) with the Kronecker extension.
      See Also:
    • removeAssign

      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<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.
    • binUi

      public MPZ binUi(long k)
      Return an MPZ whose value is the binomial coefficient this over k. Negative values of this are supported as in binUiAssign(it.unich.jgmp.MPZ,long).
    • 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:
      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:
      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.
    • randomAssign

      @Deprecated public 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.
      Set this MPZ to 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.
      Returns:
      this MPZ.
    • 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, 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, 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:
    • bufferExport

      public 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:
      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:
      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(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:
      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(String str)
      Set this MPZ to the value represented by the string str in decimal base.
      Throws:
      NumberFormatException - if str is not a valid number representation in decimal base.
      See Also:
    • setValue

      public MPZ setValue(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 Comparable<MPZ>
    • equals

      public boolean equals(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 Object
    • hashCode

      public int hashCode()
      Return a hash code value for this MPZ.
      Overrides:
      hashCode in class 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 Number
    • intValue

      public int intValue()
      Convert this MPZ to a signed int, truncating if necessary.
      Specified by:
      intValue in class 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 Number
    • floatValue

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

      public 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 String toString()
      Convert this MPZ to its decimal string representation.
      Overrides:
      toString in class Object
    • writeObject

      private void writeObject(ObjectOutputStream out) throws IOException
      Throws:
      IOException
    • readObject

      private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException
    • readObjectNoData

      private void readObjectNoData() throws ObjectStreamException
      Throws:
      ObjectStreamException