Package it.unich.jgmp
Class MPZ
- java.lang.Object
-
- java.lang.Number
-
- it.unich.jgmp.MPZ
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<MPZ>
public class MPZ extends java.lang.Number implements java.lang.Comparable<MPZ>
Multi-precision integer number. This class encapsulates thempz_tdata type, see the Integer Functions page of the GMP manual. In determining the names and prototypes of the methods of theMPZclass, we adopt the rules described in the documentation of theit.unich.jgmppackage, enriched with the following ones:- the functions in the categories I/O of Integers, Integer
Import and Export and Special Functions are not exposed by the
MPZclass.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classMPZ.MPZCleanerCleaning action for theMPZclass.static classMPZ.PrimalityStatusResult enumeration for theisProbabPrime(int)method.
-
Field Summary
Fields Modifier and Type Field Description private MpzTmpzNativeThe pointer to the nativempz_tobject.private static longserialVersionUIDVersion for serializability.
-
Constructor Summary
Constructors Modifier Constructor Description MPZ()Build anMPZwhose value is zero.MPZ(double op)Build anMPZwhose value is the truncation ofop.MPZ(long op)Build anMPZwhose value isop.MPZ(MPF op)Build anMPZwhose value is the truncation ofop.MPZ(MPQ op)Build anMPZwhose value is the truncation ofop.MPZ(MPZ op)Build anMPZwhose value isop.privateMPZ(MpzT pointer)A private constructor which build anMPZstarting from a pointer to its native data object.MPZ(java.lang.String str)Build anMPZwhose value is the number represented by the stringstrin decimal base.MPZ(java.lang.String str, int base)Build anMPZwhose value is the number represented by the stringstrin the specifiedbase.MPZ(java.math.BigInteger op)Builds anMPZwhose value is the same asop.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description MPZabs()Return anMPZwhose value is the absolute value ofthis.MPZabsAssign()Set thisMPZto its absolute value.MPZabsAssign(MPZ op)Set thisMPZto the absolute value ofop.MPZadd(MPZ op)Return anMPZwhose value is(this + op).MPZaddAssign(MPZ op)Set thisMPZto(this + op)MPZaddAssign(MPZ op1, MPZ op2)Set thisMPZto(op1 + op2).MPZaddmul(MPZ op1, MPZ op2)Return anMPZwhose value is(this + op1 * op2).MPZaddmulAssign(MPZ op1, MPZ op2)Add(op1 * op2)to thisMPZ.MPZaddmulUi(MPZ op1, long op2)Return anMPZwhose value is(this + op1 * op2).MPZaddmulUiAssign(MPZ op1, long op2)Add(op1 * op2)to thisMPZ.MPZaddUi(long op)Return anMPZwhose value is(this + op).MPZaddUiAssign(long op)Set thisMPZto(this + op)MPZaddUiAssign(MPZ op1, long op2)Set thisMPZto(op1 + op2).MPZand(MPZ op)Return anMPZwhose value is(this & op).MPZandAssign(MPZ op)Set thisMPZto(this & op).MPZandAssign(MPZ op1, MPZ op2)Set thisMPZto(op1 & op2).MPZbinUi(long k)Return anMPZwhose value is the binomial coefficientthisoverk.MPZbinUiAssign(long k)Set thisMPZto the binomial coefficientthisoverk.MPZbinUiAssign(MPZ n, long k)Set thisMPZto the binomial coefficientnoverk.static MPZbinUiUi(long n, long k)Return anMPZwhose value is the binomial coefficientnoverk.MPZbinUiUiAssign(long n, long k)Set thisMPZto the binomial coefficientnoverk.java.nio.ByteBufferbufferExport(int order, int size, int endian, long nails)Return aByteBufferfilled with word data from thisMPZ.static MPZbufferImport(int order, int size, int endian, long nails, java.nio.ByteBuffer op)Return anMPZwhose value is determined from the buffer of word data atop.MPZbufferImportAssign(int order, int size, int endian, long nails, java.nio.ByteBuffer op)Set thisMPZfrom the buffer of word data atop.MPZcdivq(MPZ d)Return anMPZwhose value is the quotient of the integer division(this / d), rounded towards +∞.MPZcdivq2Exp(long b)Return anMPZwhose value is the quotient of the integer division(this / 2b), rounded towards +∞.MPZcdivq2ExpAssign(long b)Set thisMPZto the quotient of the integer division(this / 2b), rounded toward +∞.MPZcdivq2ExpAssign(MPZ n, long b)Set thisMPZto the quotient of the integer division(n / 2b), rounded toward +∞.MPZcdivqAssign(MPZ d)Set thisMPZto the quotient of the integer division(this / d), rounded towards +∞.MPZcdivqAssign(MPZ n, MPZ d)Set thisMPZto the quotient of the integer division(n / d), rounded towards +∞.org.javatuples.Pair<MPZ,MPZ>cdivqr(MPZ d)Return a pair ofMPZs whose values are the quotient and remainder of the integer division(this / d), rounded towards +∞.MPZcdivqrAssign(MPZ r, MPZ d)Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards +∞.MPZcdivqrAssign(MPZ r, MPZ n, MPZ d)Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards +∞.longcdivqrUiAssign(MPZ r, long d)Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards +∞; it also returns the remainder.longcdivqrUiAssign(MPZ r, MPZ n, long d)Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards +∞; it also returns the remainder.longcdivqUiAssign(long d)Set thisMPZto the quotient of the integer division(this / d), rounded towards +∞; it also returns the remainder.longcdivqUiAssign(MPZ n, long d)Set thisMPZto the quotient of the integer division(n / d), rounded towards +∞; it also Return the remainder.MPZcdivr(MPZ d)Return anMPZwhose value is the remainder of the integer division(this / d), rounded towards +∞.MPZcdivr2Exp(long b)Return anMPZwhose value is the remainder of the integer division(this / 2b), rounded towards +∞.MPZcdivr2ExpAssign(long b)Set thisMPZto the remainder of the integer division(this / 2b), rounded toward +∞.MPZcdivr2ExpAssign(MPZ n, long b)Set thisMPZto the remainder of the integer division(n / 2b), rounded toward +∞.MPZcdivrAssign(MPZ d)Set thisMPZto the remainder of the integer division(this / d), rounded towards +∞.MPZcdivrAssign(MPZ n, MPZ d)Set thisMPZto the remainder of the integer division(n / d), rounded towards +∞.longcdivrUiAssign(long d)Set thisMPZto the remainder of the integer division(this / d), rounded towards +∞; it also returns the remainder.longcdivrUiAssign(MPZ n, long d)Set thisMPZto the remainder of the integer division(n / d), rounded towards +∞; it also returns the remainder.longcdivUi(long d)Return the remainder of the integer division(this / d), rounded towards +∞.MPZclrbit(long index)Return anMPZwhose value is(this & ~ 2index).MPZclrbitAssign(long index)Clear the bitindexof thisMPZ.intcmp(double op)Comparethiswithop.intcmp(long op)Comparethiswithop.intcmp(MPZ op)Comparethiswithop.intcmpabs(double op)Compare the absolute values ofthisandop.intcmpabs(MPZ op)Compare the absolute values ofthisandop.intcmpabsUi(long op)Compare the absolute values ofthisandop.intcmpUi(long op)Comparethiswithop.MPZcom()Return anMPZwhose value is(~ op).MPZcomAssign()Set thisMPZto(~ this).MPZcomAssign(MPZ op)Set thisMPZto(~ op).MPZcombit(long index)Return anMPZwhose value is(this ^ 2index).MPZcombitAssign(long index)Complement the bitindexof thisMPZ.intcompareTo(MPZ op)Compare thisMPZwithop.static MPZdfacUi(long n)Return anMPZwhose value the double factorial ofn.MPZdfacUiAssign(long n)Set thisMPZto the double factorial ofn.MPZdivexact(MPZ d)Return anMPZwhose value is the quotient of(this / d).MPZdivexactAssign(MPZ d)Set thisMPZto the quotient of(this / d).MPZdivexactAssign(MPZ n, MPZ d)Set thisMPZto the quotient of(n / d).MPZdivexactUi(long d)Return anMPZwhose value is the quotient of(this / d).MPZdivexactUiAssign(long d)Set thisMPZto the quotient of(this / d).MPZdivexactUiAssign(MPZ n, long d)Set thisMPZto the quotient of(n / d).doubledoubleValue()Convert thisMPZto a double, truncating if necessary.booleanequals(java.lang.Object obj)Compare thisMPZwith the objectopfor equality.static MPZfacUi(long n)Return anMPZwhose value is the factorial ofn.MPZfacUiAssign(long n)Set thisMPZto the factorial ofn.MPZfdivq(MPZ d)Return anMPZwhose value is the quotient of the integer division(this / d), rounded towards -∞.MPZfdivq2Exp(long b)Return anMPZwhose value is the quotient of the integer division(this / 2b), rounded towards -∞.MPZfdivq2ExpAssign(long b)Set thisMPZto the quotient of the integer division(this / 2b), rounded toward -∞.MPZfdivq2ExpAssign(MPZ n, long b)Set thisMPZto the quotient of the integer division(n / 2b), rounded toward -∞.MPZfdivqAssign(MPZ d)Set thisMPZto the quotient of the integer division(this / d), rounded towards -∞.MPZfdivqAssign(MPZ n, MPZ d)Set thisMPZto the quotient of the integer division(n / d), rounded towards -∞.org.javatuples.Pair<MPZ,MPZ>fdivqr(MPZ d)Return twoMPZs whose values are the quotient and remainder of the integer division(this / d), rounded towards -∞.MPZfdivqrAssign(MPZ r, MPZ d)Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards -∞.MPZfdivqrAssign(MPZ r, MPZ n, MPZ d)Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards -∞.longfdivqrUiAssign(MPZ r, long d)Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards -∞; it also returns the absolute value of the remainder.longfdivqrUiAssign(MPZ r, MPZ n, long d)Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards -∞; it also returns the absolute value of the remainder.longfdivqUiAssign(long d)Set thisMPZto the quotient of the integer division(this / d), rounded towards -∞; it also returns the absolute value of the remainder.longfdivqUiAssign(MPZ n, long d)Set thisMPZto the quotient of the integer division(n / d), rounded towards -∞; it also returns the absolute value of the remainder.MPZfdivr(MPZ d)Return anMPZwhose value is the remainder of the integer division(this / d), rounded towards -∞.MPZfdivr2Exp(long b)Return anMPZwhose value is the remainder of the integer division(this / 2b), rounded towards -∞.MPZfdivr2ExpAssign(long b)Set thisMPZto the remainder of the integer division(this / 2b), rounded toward -∞.MPZfdivr2ExpAssign(MPZ n, long b)Set thisMPZto the remainder of the integer division(n / 2b), rounded toward -∞.MPZfdivrAssign(MPZ d)Set thisMPZto the remainder of the integer division(this / d), rounded towards -∞.MPZfdivrAssign(MPZ n, MPZ d)Set thisMPZto the remainder of the integer division(n / d), rounded towards -∞.longfdivrUiAssign(long d)Set thisMPZto the remainder of the integer division(this / d), rounded towards -∞; it also returns the absolute value of the remainder.longfdivrUiAssign(MPZ n, long d)Set thisMPZto the remainder of the integer division(n / d), rounded towards -∞; it also returns the absolute value of the remainder.longfdivUi(long d)Return the remainder of the integer division(this / d), rounded towards -∞.static org.javatuples.Pair<MPZ,MPZ>fib2Ui(long n)Return twoMPZwhose values are then-th and(n-1)-th Fibonacci numbers.MPZfib2UiAssign(MPZ fnsub1, long n)Set the value ofthisandfnsub1to then-th and(n-1)-th Fibonacci numbers respecively.static MPZfibUi(long n)Return anMPZwhose value is then-th Fibonacci number.MPZfibUiAssign(long n)Set thisMPZto then-th Fibonacci number.booleanfitsSint()Returntrueif and only if thisMPZfits into a native signed int.booleanfitsSlong()Returntrueif and only if thisMPZfits into a native signed long.booleanfitsSshort()Returntrueif and only if thisMPZfits into a native signed short.booleanfitsUint()Returntrueif and only if thisMPZfits into a native unsigned int.booleanfitsUlong()Returntrueif and only if thisMPZfits into a native unsigned long.booleanfitsUshort()Returntrueif and only if thisMPZfits into a native unsigned short.floatfloatValue()Convert thisMPZto a float, truncating if necessary.MPZgcd(MPZ op)Return anMPZwhose value is the greatest commond divisor ofthisandop.MPZgcdAssign(MPZ op)Set thisMPZto the greatest commond divisor ofthisandop.MPZgcdAssign(MPZ op1, MPZ op2)Set thisMPZto the greatest commond divisor ofop1andop2.org.javatuples.Triplet<MPZ,MPZ,MPZ>gcdext(MPZ op)Return the greatest common divisor ofthisandop, together with numberssandtsatisfying(a*this + b*op = g)See the GMP functionmpz_gcdext.MPZgcdextAssign(MPZ s, MPZ t, MPZ op)Set thisMPZto the greatest common divisor ofthisandop, and in addition Setsandtto coefficients satisfying(this*s + op*t = gcd).MPZgcdextAssign(MPZ s, MPZ t, MPZ a, MPZ b)Set thisMPZto the greatest common divisor ofaandb, and in addition Setsandtto coefficients satisfying(a*s + b*t = gcd).longgcdUi(long op)Return the greatest commond divisor ofthisandop.longgcdUiAssign(long op)Set thisMPZto the greatest commond divisor ofop1andop2, and returns it.longgcdUiAssign(MPZ op1, long op2)Set thisMPZto the greatest commond divisor ofop1andop2, and return it.java.math.BigIntegergetBigInteger()Converts thisMPZto BigInteger.doublegetD()Convert thisMPZto a double, truncating if necessary.org.javatuples.Pair<java.lang.Double,java.lang.Long>getD2Exp()Convert thisMPZto a pair made of mantissa and exponent, truncating if necessary.MpzTgetNative()Return the native pointer to the GMP object.longgetSi()Convert thisMPZto a signed long.java.lang.StringgetStr(int base)Return the String representation of thisMPZin the specifiedbase, ornullif the base is not valid.longgetUi()Convert thisMPZto an unsigned long.longhamdist(MPZ op)Ifthisandopare both>= 0or both< 0, return the Hamming distance between them, which is the number of bit positions wherethisandophave different bit values.inthashCode()Return a hash code value for thisMPZ.static MPZinit()Return anMPZwhose value is zero.static MPZinit2(long n)Return anMPZwhose value is zero, with pre-allocated space forn-bit numbers.static MPZinitSet(double op)Return anMPZwhose value is the truncation ofop.static MPZinitSet(long op)Return anMPZwhose value isop.static MPZinitSet(MPZ op)Return anMPZwhose value isop.static org.javatuples.Pair<java.lang.Integer,MPZ>initSet(java.lang.String str, int base)Return anMPZwhose value is the number represented by the stringstrin the specifiedbase.static MPZinitSetUi(long op)Return anMPZwhose value isop.intintValue()Convert thisMPZto a signed int, truncating if necessary.java.util.Optional<MPZ>invert(MPZ op)Optionally return, when it exists, anMPZwhose value is the inverse ofthismoduloop.booleaninvertAssign(MPZ op)Set thisMPZto the inverse ofthismoduloop.booleaninvertAssign(MPZ op1, MPZ op2)Set thisMPZto the inverse ofop1moduloop2.MPZior(MPZ op)Return anMPZwhose value is(this | op).MPZiorAssign(MPZ op)Set thisMPZto(this | op).MPZiorAssign(MPZ op1, MPZ op2)Set thisMPZto(op1 | op2).booleanisCongruent(MPZ c, MPZ d)Returntrueif and only ifthisis congruent tocmodulod.booleanisCongruent2Exp(MPZ c, long b)Returntrueif and only ifthisis congruent tocmodulo2b.booleanisCongruentUi(long c, long d)Returntrueif and only ifthisis congruent tocmodulod.booleanisDivisible(MPZ d)Returntrueif and only ifthisis exactly divisible byd.booleanisDivisible2Exp(long b)Returntrueif and only ifthisis exactly divisible by2b.booleanisDivisibleUi(long d)Returntrueif and only ifthisis exactly divisible byd.booleanisEven()Returntrueif and only if thisMPZis evenbooleanisOdd()Returntrueif and only if thisMPZis odd.booleanisPerfectPower()Returntrueif and only if this number is a perfect power, i.e., if there exist integersaandb, with(b > 1), such thatthisequals(ab).booleanisPerfectSquare()Returntrueif and only if this number is a perfect square.MPZ.PrimalityStatusisProbabPrime(int reps)Returntrueif and only ifthisis prime.booleanisZero()Returntrueif and only if thisMPZis zero.intjacobi(MPZ b)Return the Jacobi symbol(this / b).intkronecker(long b)Return the Jacobi symbol(this / b)with the Kronecker extension.intkronecker(MPZ b)Return the Jacobi symbol(this / n)with the Kronecker extension(this/2)=(2/this)whenthisis odd, or(this/2)=0whenthisis even.intkroneckerReverse(long a)Return the Jacobi symbol(a / this)with the Kronecker extension.intkroneckerUi(long b)Return the Jacobi symbol(this / b)with the Kronecker extension.MPZlcm(MPZ op)Return anMPZwhose value is the least common multiple ofthisandop.MPZlcmAssign(MPZ op)Set thisMPZto the least common multiple ofthisandop.MPZlcmAssign(MPZ op1, MPZ op2)Set thisMPZto the least common multiple ofop1andop2.MPZlcmUi(long op)Return the least common multiple ofthisandop.MPZlcmUiAssign(long op)Set thisMPZto the least common multiple ofthisandop.MPZlcmUiAssign(MPZ op1, long op2)Set thisMPZto the least common multiple ofop1andop2.intlegendre(MPZ p)Return the Legendre symbol(this / p).longlongValue()Convert thisMPZto a signed long.static org.javatuples.Pair<MPZ,MPZ>lucnum2Ui(long n)Return twoMPZwhose values are then-th and(n-1)-th Lucas numbers.MPZlucnum2UiAssign(MPZ fnsub1, long n)Set the value ofthisandfnsub1to then-th and(n-1)-th Lucas numbers respecively.static MPZlucnumUi(long n)Return anMPZwhose value is then-th Lucas number.MPZlucnumUiAssign(long n)Set thisMPZto then-th Lucas number.static MPZmfacUiUi(long n, long m)Return anMPZwhose value is them-multi factorial ofn.MPZmfacUiUiAssign(long n, long m)Set thisMPZto them-multi factorial ofn.MPZmod(MPZ d)Return anMPZwhose value is(this mod d).MPZmodAssign(MPZ d)Set thisMPZto(this mod d).MPZmodAssign(MPZ n, MPZ d)Set thisMPZto(n mod d).longmodUi(long d)Return anMPZwhose value is(this mod d).longmodUiAssign(long d)Set thisMPZto(n mod d); it also returns the result.longmodUiAssign(MPZ n, long d)Set thisMPZto(n mod d); it also returns the result.MPZmul(long op)Return anMPZwhose value is(this * op).MPZmul(MPZ op)Return anMPZwhose value is(this * op).MPZmul2Exp(long b)Return anMPZwhose value is(this * 2b).MPZmul2ExpAssign(long b)Set thisMPZto(this * 2b).MPZmul2ExpAssign(MPZ op, long b)Set thisMPZto(op * 2b).MPZmulAssign(long op)Set thisMPZto(this * op)MPZmulAssign(MPZ op)Set thisMPZto(this * op)MPZmulAssign(MPZ op1, long op2)Set thisMPZto(op1 * op2).MPZmulAssign(MPZ op1, MPZ op2)Set thisMPZto(op1 * op2).MPZmulUi(long op)Return anMPZwhose value is(this * op).MPZmulUiAssign(long op)Set thisMPZto(this * op)MPZmulUiAssign(MPZ op1, long op2)Set thisMPZto(op1 * op2).MPZneg()Return anMPZwhose value is the quotient of(- this).MPZnegAssign()Set thisMPZto its opposite.MPZnegAssign(MPZ op)Set thisMPZto(- op).MPZnextprime()Return anMPZwhose value is the next prime greater thenthis.MPZnextprimeAssign()Set thisMPZto the next prime greater then itself.MPZnextprimeAssign(MPZ op)Set thisMPZto the next prime greater thenop.longpopcount()If thisMPZis non-negative, return its population count, which is the number of1bits in its binary representation.MPZpowm(MPZ exp, MPZ mod)Return anMPZwhose value is(thisexp)modulomod.MPZpowmAssign(MPZ exp, MPZ mod)Set thisMPZto(thisexp)modulomod.MPZpowmAssign(MPZ base, MPZ exp, MPZ mod)Set thisMPZto(baseexp)modulomod.MPZpowmSec(MPZ exp, MPZ mod)Return anMPZwhose value is(thisexp)modulomod.MPZpowmSecAssign(MPZ exp, MPZ mod)Set thisMPZto(thisexp)modulomod.MPZpowmSecAssign(MPZ base, MPZ exp, MPZ mod)Set thisMPZto(baseexp)modulomod.MPZpowmUi(long exp, MPZ mod)Return anMPZwhose value is(thisexp)modulomod.MPZpowmUiAssign(long exp, MPZ mod)Set thisMPZto(thisexp)modulomod.MPZpowmUiAssign(MPZ base, long exp, MPZ mod)Set thisMPZto(baseexp)modulomod.MPZpowUi(long exp)Return anMPZwhose value is(thisexp).static MPZpowUi(long base, long exp)Return anMPZwhose value is(baseexp).MPZpowUiAssign(long exp)Set thisMPZto(thisexp).MPZpowUiAssign(long base, long exp)Set thisMPZto(baseexp).MPZpowUiAssign(MPZ base, long exp)Set thisMPZto(baseexp).static MPZprimorialUi(long n)Return anMPZwhose value is the primorial ofn, i.e., the product of all positive prime numbers<= n.MPZprimorialUiAssign(long n)Set thisMPZto the primorial ofn, i.e., the product of all positive prime numbers<= n.static MPZrandom(long max_size)Deprecated.useurandomb(it.unich.jgmp.RandState,long)orurandomm(it.unich.jgmp.RandState,it.unich.jgmp.MPZ)instead, since this method uses a global random state and it is not reentrant.static MPZrandom2(long max_size)Deprecated.userrandomb(it.unich.jgmp.RandState,long)instead, since this method uses a global random state and it is not reentrant.MPZrandom2Assign(long max_size)Deprecated.userrandombAssign(it.unich.jgmp.RandState,long)instead, since this method uses a global random state and it is not reentrant.MPZrandomAssign(long max_size)Deprecated.useurandombAssign(it.unich.jgmp.RandState,long)orurandommAssign(it.unich.jgmp.RandState,it.unich.jgmp.MPZ)instead, since this method uses a global random state and it is not reentrant.private voidreadObject(java.io.ObjectInputStream in)private voidreadObjectNoData()MPZrealloc2(long n)Changes the space allocated for this number tonbits.org.javatuples.Pair<java.lang.Long,MPZ>remove(MPZ f)Return the result of removing the factorffromthis, together with the number of occurrences which were removed.longremoveAssign(MPZ f)Remove all occurrences of the factorffromthisMPZ.longremoveAssign(MPZ op, MPZ f)Remove all occurrences of the factorffromopand stores the result in thisMPZ.org.javatuples.Pair<java.lang.Boolean,MPZ>root(long n)Return anMPZwhose value is the truncated integer part of thenth root ofthis, and a boolean flag which is true when the result is exact.booleanrootAssign(long n)Set thisMPZto the truncated integer part of itsnth root.booleanrootAssign(MPZ op, long n)Set thisMPZto the truncated integer part of thenth root ofop.org.javatuples.Pair<MPZ,MPZ>rootrem(long n)Return twoMPZs whose values are the truncated integer part of thenth root ofthisand the remainder, i.e.,(u - rootn).MPZrootremAssign(MPZ rem, long n)Set thisMPZto the truncated integer part of the itsnth root andremto the remainder, i.e.,(this - rootn).MPZrootremAssign(MPZ rem, MPZ u, long n)Set thisMPZto the truncated integer part of thenth root ofuandremto the remainder, i.e.,(u - rootn).static MPZrrandomb(RandState s, long n)Return anMPZwhose value is a random integer with long strings of zeros and ones in the binary representation.MPZrrandombAssign(RandState s, long n)Set thisMPZto a random integer with long strings of zeros and ones in the binary representation.longscan0(long starting_bit)Scan thisMPZ, starting from bitstarting_bit, towards more significant bits, until the first0bit is found.longscan1(long starting_bit)Scanthis, starting from bitstarting_bit, towards more significant bits, until the first1bit is found.MPZset(double op)Set thisMPZto the truncation ofop.MPZset(long op)Set thisMPZtoop.MPZset(MPF op)Set thisMPZto the truncation ofop.MPZset(MPQ op)Set thisMPZto the truncation ofop.MPZset(MPZ op)Set thisMPZtoop.(package private) static voidset(MpzT mpzNative, java.math.BigInteger op)intset(java.lang.String str, int base)Set thisMPZto the number represented by the stringstrin the specifiedbase.MPZset(java.math.BigInteger op)Sets thisMPZtoop.MPZsetbit(long index)Return anMPZwhose value is(this | 2index).MPZsetbitAssign(long index)Set the bitindexof thisMPZ.MPZsetUi(long op)Set thisMPZtoop.MPZsetValue(double op)Set thisMPZto the truncation opop.MPZsetValue(long op)Set thisMPZto signed longop.MPZsetValue(MPF op)Set thisMPZto the truncation opop.MPZsetValue(MPQ op)Set thisMPZto the truncation opop.MPZsetValue(MPZ op)Set thisMPZtoop.MPZsetValue(java.lang.String str)Set thisMPZto the value represented by the stringstrin decimal base.MPZsetValue(java.lang.String str, int base)Set thisMPZto the number represented by the stringstrin the specifiedbase.MPZsetValue(java.math.BigInteger op)Sets thisMPZtoop.intsgn()Return+1if(this > 0),0if(this = 0)and-1ifthis < 0.longsizeinbase(int base)Return the size of thisMPZmeasured in number of digits in the specifiedbase.MPZsqrt()Return anMPZwhose value is the truncated integer part of the square root ofthis.MPZsqrtAssign()Set thisMPZto the truncated integer part of its square root.MPZsqrtAssign(MPZ op)Set thisMPZto the truncated integer part of the square root ofop.org.javatuples.Pair<MPZ,MPZ>sqrtrem()Return twoMPZs whose values are the truncated integer part of the square root ofthisand the remainder, i.e.,(op - root2).MPZsqrtremAssign(MPZ rem)Set thisMPZto the truncated integer part of its square root andremto the remainder, i.e.,(this - root2).MPZsqrtremAssign(MPZ rem, MPZ op)Set thisMPZto the truncated integer part of the square root ofopandremto the remainder, i.e.,(op - root2).MPZsub(MPZ op)Return anMPZwhose value is(this - op).MPZsubAssign(MPZ op)Set thisMPZto(this - op)MPZsubAssign(MPZ op1, MPZ op2)Set thisMPZto(op1 - op2).MPZsubmul(MPZ op1, MPZ op2)Return anMPZwhose value is(this - op1 * op2).MPZsubmulAssign(MPZ op1, MPZ op2)Subtract(op1 * op2)to thisMPZ.MPZsubmulUi(MPZ op1, long op2)Return anMPZwhose value is(this - op1 * op2).MPZsubmulUiAssign(MPZ op1, long op2)Subtract(op1 * op2)to thisMPZ.MPZsubUi(long op)Return anMPZwhose value is(this - op).MPZsubUiAssign(long op)Set thisMPZto(this - op)MPZsubUiAssign(MPZ op1, long op2)Set thisMPZto(op1 - op2).MPZswap(MPZ op)Swap the value of thisMPZwith the value ofop.MPZtdivq(MPZ d)Return anMPZwhose value is the quotient of the integer division(this / d), rounded towards zero.MPZtdivq2Exp(long b)Return anMPZwhose value is the quotient of the integer division(this / 2b), rounded towards zero.MPZtdivq2ExpAssign(long b)Set thisMPZto the quotient of the integer division(this / 2b), rounded toward zero.MPZtdivq2ExpAssign(MPZ n, long b)Set thisMPZto the quotient of the integer division(n / 2b), rounded toward zero.MPZtdivqAssign(MPZ d)Set thisMPZto the quotient of the integer division(this / d), rounded towards zero.MPZtdivqAssign(MPZ n, MPZ d)Set thisMPZto the quotient of the integer division(n / d), rounded towards zero.org.javatuples.Pair<MPZ,MPZ>tdivqr(MPZ d)Return twoMPZs whose values are the quotient and remainder of the integer division(this / d), rounded towards zero.MPZtdivqrAssign(MPZ r, MPZ d)Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards zero.MPZtdivqrAssign(MPZ r, MPZ n, MPZ d)Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards zero.longtdivqrUiAssign(MPZ r, long d)Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards zero; it also returns the absolute value of the remainder.longtdivqrUiAssign(MPZ r, MPZ n, long d)Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards zero; it also returns the absolute value of the remainder.longtdivqUiAssign(long d)Set thisMPZto the quotient of the integer division(this / d), rounded towards zero; it also returns the absolute value of the remainder.longtdivqUiAssign(MPZ n, long d)Set thisMPZto the quotient of the integer division(n / d), rounded towards zero; it also returns the absolute value of the remainder.MPZtdivr(MPZ d)Return anMPZwhose value is the remainder of the integer division(this / d), rounded towards zero.MPZtdivr2Exp(long b)Return anMPZwhose value is the remainder of the integer division(this / 2b), rounded towards zero.MPZtdivr2ExpAssign(long b)Set thisMPZto the remainder of the integer division(this / 2b), rounded toward zero.MPZtdivr2ExpAssign(MPZ n, long b)Set thisMPZto the remainder of the integer division(n / 2b), rounded toward zero.MPZtdivrAssign(MPZ d)Set thisMPZto the remainder of the integer division(this / d), rounded towards zero.MPZtdivrAssign(MPZ n, MPZ d)Set thisMPZto the remainder of the integer division(n / d), rounded towards zero.longtdivrUiAssign(long d)Set thisMPZto the remainder of the integer division(this / d), rounded towards zero; it also returns the absolute value of the remainder.longtdivrUiAssign(MPZ n, long d)Set thisMPZto the remainder of the integer division(n / d), rounded towards zero; it also returns the absolute value of the remainder.longtdivUi(long d)Return the remainder of the integer division(this / d), rounded towards zero.java.lang.StringtoString()Convert thisMPZto its decimal string representation.java.lang.StringtoString(int base)Convert thisMPZto its string representation in the specifiedbase, ornullif the base is not valid.inttstbit(long index)Return the bitindexof thisMPZ.intuiKronecker(long a)Return the Jacobi symbol(a / this)with the Kronecker extension.MPZuiSub(long op)Return anMPZwhose value is(op - this).MPZuiSubAssign(long op)Set thisMPZto(op - this)MPZuiSubAssign(long op1, MPZ op2)Set thisMPZto(op1 - op2).static MPZurandomb(RandState s, long n)Return anMPZwhose value is an uniformly distributed random integer in the range0} to(2n - 1), inclusive.MPZurandombAssign(RandState s, long n)Set thisMPZto a uniformly distributed random integer in the range0to(2n - 1), inclusive.static MPZurandomm(RandState s, MPZ n)Return anMPZwhose value is an uniformly distributed random integer in the range0to(n - 1), inclusive.MPZurandommAssign(RandState s, MPZ n)Set thisMPZto a uniformly distributed random integer in the range0to(n - 1), inclusive.private voidwriteObject(java.io.ObjectOutputStream out)MPZxor(MPZ op)Return anMPZwhose value is(this ^ op).MPZxorAssign(MPZ op)Set thisMPZto(this ^ op).MPZxorAssign(MPZ op1, MPZ op2)Set thisMPZto(op1 ^ op2).
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Version for serializability.- See Also:
- Constant Field Values
-
mpzNative
private transient MpzT mpzNative
The pointer to the nativempz_tobject.
-
-
Constructor Detail
-
MPZ
private MPZ(MpzT pointer)
A private constructor which build anMPZstarting from a pointer to its native data object. The native object needs to be already initialized.
-
MPZ
public MPZ()
Build anMPZwhose value is zero.
-
MPZ
public MPZ(MPZ op)
Build anMPZwhose value isop.
-
MPZ
public MPZ(long op)
Build anMPZwhose value isop.
-
MPZ
public MPZ(double op)
Build anMPZwhose value is the truncation ofop.- Throws:
java.lang.ArithmeticException- ifopis not a finite number.
-
MPZ
public MPZ(MPQ op)
Build anMPZwhose value is the truncation ofop.
-
MPZ
public MPZ(MPF op)
Build anMPZwhose value is the truncation ofop.
-
MPZ
public MPZ(java.lang.String str, int base)Build anMPZwhose value is the number represented by the stringstrin the specifiedbase. See the GMP functionmpz_init_set_str.- Throws:
java.lang.NumberFormatException- if eitherbaseis not valid orstris not a valid string in the specifiedbase.
-
MPZ
public MPZ(java.lang.String str)
Build anMPZwhose value is the number represented by the stringstrin decimal base. See the GMP functionmpz_init_set_str.- Throws:
java.lang.NumberFormatException- ifstris not a valid number representation in decimal base.
-
MPZ
public MPZ(java.math.BigInteger op)
Builds anMPZwhose value is the same asop.
-
-
Method Detail
-
getNative
public MpzT getNative()
Return the native pointer to the GMP object.
-
init
public static MPZ init()
Return anMPZwhose value is zero.
-
init2
public static MPZ init2(long n)
Return anMPZwhose value is zero, with pre-allocated space forn-bit numbers. Calling this method is never necessary; reallocation is handled automatically by GMP when needed. See the GMP functionmpz_init2.
-
realloc2
public MPZ realloc2(long n)
Changes the space allocated for this number tonbits. The value is preserved if it fits, otherwise it is set to 0. Calling this function is never necessary; reallocation is handled automatically by GMP when needed. This function can be used to increase the space for a variable in order to avoid repeated automatic reallocations, or to decrease it to give memory back to the heap.- Returns:
- this
MPZ.
-
set
public MPZ set(long op)
Set thisMPZtoop.- Returns:
- this
MPZ.
-
setUi
public MPZ setUi(long op)
Set thisMPZtoop.- Returns:
- this
MPZ.
-
set
public MPZ set(double op)
Set thisMPZto the truncation ofop.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifopis not a finite number. In this case,thisis not altered.
-
set
public int set(java.lang.String str, int base)Set thisMPZto the number represented by the stringstrin the specifiedbase. See the GMP functionmpz_set_str.- Returns:
- 0 if the operation succeeded, -1 otherwise. In the latter case,
thisis not altered.
-
set
static void set(MpzT mpzNative, java.math.BigInteger op)
-
set
public MPZ set(java.math.BigInteger op)
Sets thisMPZtoop.- Returns:
- this
MPZ.
-
initSet
public static MPZ initSet(long op)
Return anMPZwhose value isop.
-
initSetUi
public static MPZ initSetUi(long op)
Return anMPZwhose value isop.
-
initSet
public static MPZ initSet(double op)
Return anMPZwhose value is the truncation ofop.- Throws:
java.lang.ArithmeticException- ifopis not a finite number.
-
initSet
public static org.javatuples.Pair<java.lang.Integer,MPZ> initSet(java.lang.String str, int base)
Return anMPZwhose value is the number represented by the stringstrin the specifiedbase. See the GMP functionmpz_init_set_str.- Returns:
- a pair whose first component is
0if the operation succeeded, and-1if eitherbaseis not valid, orstris not a valid numeric representation in the specified base. The second component of the pair is the number represented instrif the operation succeeded,0otherwise.
-
getUi
public long getUi()
Convert thisMPZto an unsigned long. If this number is too big to fit a native unsigned long, then just the least significant bits that do fit are returned. The sign of this number is ignored, only the absolute value is used.
-
getSi
public long getSi()
Convert thisMPZto a signed long. If this number is too big to fit a native signed long, return the least significant part, preserving the sign.
-
getD
public double getD()
Convert thisMPZto a double, truncating if necessary. If the exponent from the conversion is too big, the result is system dependent. An infinity is returned where available. A hardware overflow trap may or may not occur.
-
getD2Exp
public org.javatuples.Pair<java.lang.Double,java.lang.Long> getD2Exp()
Convert thisMPZto a pair made of mantissa and exponent, truncating if necessary. See the GMP functionmpz_get_d_2exp.
-
getStr
public java.lang.String getStr(int base)
Return the String representation of thisMPZin the specifiedbase, ornullif the base is not valid. See the GMP functionmpz_get_str.
-
getBigInteger
public java.math.BigInteger getBigInteger()
Converts thisMPZto BigInteger.
-
addUiAssign
public MPZ addUiAssign(MPZ op1, long op2)
Set thisMPZto(op1 + op2).- Returns:
- this
MPZ.
-
addUiAssign
public MPZ addUiAssign(long op)
Set thisMPZto(this + op)- Returns:
- this
MPZ
-
addUi
public MPZ addUi(long op)
Return anMPZwhose value is(this + op).
-
subUiAssign
public MPZ subUiAssign(MPZ op1, long op2)
Set thisMPZto(op1 - op2).- Returns:
- this
MPZ.
-
subUiAssign
public MPZ subUiAssign(long op)
Set thisMPZto(this - op)- Returns:
- this
MPZ
-
subUi
public MPZ subUi(long op)
Return anMPZwhose value is(this - op).
-
uiSubAssign
public MPZ uiSubAssign(long op1, MPZ op2)
Set thisMPZto(op1 - op2).- Returns:
- this
MPZ.
-
uiSubAssign
public MPZ uiSubAssign(long op)
Set thisMPZto(op - this)- Returns:
- this
MPZ
-
uiSub
public MPZ uiSub(long op)
Return anMPZwhose value is(op - this).
-
mulUiAssign
public MPZ mulUiAssign(MPZ op1, long op2)
Set thisMPZto(op1 * op2).- Returns:
- this
MPZ.
-
mulUiAssign
public MPZ mulUiAssign(long op)
Set thisMPZto(this * op)- Returns:
- this
MPZ
-
mulUi
public MPZ mulUi(long op)
Return anMPZwhose value is(this * op).
-
mulAssign
public MPZ mulAssign(long op)
Set thisMPZto(this * op)- Returns:
- this
MPZ
-
mul
public MPZ mul(long op)
Return anMPZwhose value is(this * op).
-
addmulAssign
public MPZ addmulAssign(MPZ op1, MPZ op2)
Add(op1 * op2)to thisMPZ.- Returns:
- this
MPZ.
-
addmulUiAssign
public MPZ addmulUiAssign(MPZ op1, long op2)
Add(op1 * op2)to thisMPZ.- Returns:
- this
MPZ.
-
submulAssign
public MPZ submulAssign(MPZ op1, MPZ op2)
Subtract(op1 * op2)to thisMPZ.- Returns:
- this
MPZ.
-
submulUiAssign
public MPZ submulUiAssign(MPZ op1, long op2)
Subtract(op1 * op2)to thisMPZ.- Returns:
- this
MPZ.
-
mul2ExpAssign
public MPZ mul2ExpAssign(MPZ op, long b)
Set thisMPZto(op * 2b).- Returns:
- this
MPZ.
-
mul2ExpAssign
public MPZ mul2ExpAssign(long b)
Set thisMPZto(this * 2b).- Returns:
- this
MPZ.
-
mul2Exp
public MPZ mul2Exp(long b)
Return anMPZwhose value is(this * 2b).
-
negAssign
public MPZ negAssign()
Set thisMPZto its opposite.- Returns:
- this
MPZ.
-
neg
public MPZ neg()
Return anMPZwhose value is the quotient of(- this).
-
absAssign
public MPZ absAssign(MPZ op)
Set thisMPZto the absolute value ofop.- Returns:
- this
MPZ.
-
absAssign
public MPZ absAssign()
Set thisMPZto its absolute value.- Returns:
- this
MPZ.
-
abs
public MPZ abs()
Return anMPZwhose value is the absolute value ofthis.
-
cdivqAssign
public MPZ cdivqAssign(MPZ n, MPZ d)
Set thisMPZto the quotient of the integer division(n / d), rounded towards +∞.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
cdivqAssign
public MPZ cdivqAssign(MPZ d)
Set thisMPZto the quotient of the integer division(this / d), rounded towards +∞.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
cdivrAssign
public MPZ cdivrAssign(MPZ n, MPZ d)
Set thisMPZto the remainder of the integer division(n / d), rounded towards +∞.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
cdivrAssign
public MPZ cdivrAssign(MPZ d)
Set thisMPZto the remainder of the integer division(this / d), rounded towards +∞.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
cdivqrAssign
public MPZ cdivqrAssign(MPZ r, MPZ n, MPZ d)
Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards +∞.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.java.lang.IllegalArgumentException- ifthisandrare the same object.
-
cdivqrAssign
public MPZ cdivqrAssign(MPZ r, MPZ d)
Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards +∞.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.java.lang.IllegalArgumentException- ifthisandrare the same object.
-
cdivqUiAssign
public long cdivqUiAssign(MPZ n, long d)
Set thisMPZto the quotient of the integer division(n / d), rounded towards +∞; it also Return the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
cdivqUiAssign
public long cdivqUiAssign(long d)
Set thisMPZto the quotient of the integer division(this / d), rounded towards +∞; it also returns the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
cdivrUiAssign
public long cdivrUiAssign(MPZ n, long d)
Set thisMPZto the remainder of the integer division(n / d), rounded towards +∞; it also returns the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
cdivrUiAssign
public long cdivrUiAssign(long d)
Set thisMPZto the remainder of the integer division(this / d), rounded towards +∞; it also returns the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
cdivqrUiAssign
public long cdivqrUiAssign(MPZ r, MPZ n, long d)
Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards +∞; it also returns the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.java.lang.IllegalArgumentException- ifthisandrare the same object.
-
cdivqrUiAssign
public long cdivqrUiAssign(MPZ r, long d)
Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards +∞; it also returns the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.java.lang.IllegalArgumentException- ifthisandrare the same object.
-
cdivUi
public long cdivUi(long d)
Return the remainder of the integer division(this / d), rounded towards +∞.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
cdivq2ExpAssign
public MPZ cdivq2ExpAssign(MPZ n, long b)
Set thisMPZto the quotient of the integer division(n / 2b), rounded toward +∞.- Returns:
- this
MPZ.
-
cdivq2ExpAssign
public MPZ cdivq2ExpAssign(long b)
Set thisMPZto the quotient of the integer division(this / 2b), rounded toward +∞.- Returns:
- this
MPZ.
-
cdivr2ExpAssign
public MPZ cdivr2ExpAssign(MPZ n, long b)
Set thisMPZto the remainder of the integer division(n / 2b), rounded toward +∞.- Returns:
- this
MPZ.
-
cdivr2ExpAssign
public MPZ cdivr2ExpAssign(long b)
Set thisMPZto the remainder of the integer division(this / 2b), rounded toward +∞.- Returns:
- this
MPZ.
-
cdivq
public MPZ cdivq(MPZ d)
Return anMPZwhose value is the quotient of the integer division(this / d), rounded towards +∞.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
cdivr
public MPZ cdivr(MPZ d)
Return anMPZwhose value is the remainder of the integer division(this / d), rounded towards +∞.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
cdivqr
public org.javatuples.Pair<MPZ,MPZ> cdivqr(MPZ d)
Return a pair ofMPZs whose values are the quotient and remainder of the integer division(this / d), rounded towards +∞.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
cdivq2Exp
public MPZ cdivq2Exp(long b)
Return anMPZwhose value is the quotient of the integer division(this / 2b), rounded towards +∞.
-
cdivr2Exp
public MPZ cdivr2Exp(long b)
Return anMPZwhose value is the remainder of the integer division(this / 2b), rounded towards +∞.
-
fdivqAssign
public MPZ fdivqAssign(MPZ n, MPZ d)
Set thisMPZto the quotient of the integer division(n / d), rounded towards -∞.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
fdivqAssign
public MPZ fdivqAssign(MPZ d)
Set thisMPZto the quotient of the integer division(this / d), rounded towards -∞.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
fdivrAssign
public MPZ fdivrAssign(MPZ n, MPZ d)
Set thisMPZto the remainder of the integer division(n / d), rounded towards -∞.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
fdivrAssign
public MPZ fdivrAssign(MPZ d)
Set thisMPZto the remainder of the integer division(this / d), rounded towards -∞.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
fdivqrAssign
public MPZ fdivqrAssign(MPZ r, MPZ n, MPZ d)
Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards -∞.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.java.lang.IllegalArgumentException- ifthisandrare the same object.
-
fdivqrAssign
public MPZ fdivqrAssign(MPZ r, MPZ d)
Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards -∞.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.java.lang.IllegalArgumentException- ifthisandrare the same object.
-
fdivqUiAssign
public long fdivqUiAssign(MPZ n, long d)
Set thisMPZto the quotient of the integer division(n / d), rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
fdivqUiAssign
public long fdivqUiAssign(long d)
Set thisMPZto the quotient of the integer division(this / d), rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
fdivrUiAssign
public long fdivrUiAssign(MPZ n, long d)
Set thisMPZto the remainder of the integer division(n / d), rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
fdivrUiAssign
public long fdivrUiAssign(long d)
Set thisMPZto the remainder of the integer division(this / d), rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
fdivqrUiAssign
public long fdivqrUiAssign(MPZ r, MPZ n, long d)
Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.java.lang.IllegalArgumentException- ifthisandrare the same object.
-
fdivqrUiAssign
public long fdivqrUiAssign(MPZ r, long d)
Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards -∞; it also returns the absolute value of the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.java.lang.IllegalArgumentException- ifthisandrare the same object.
-
fdivUi
public long fdivUi(long d)
Return the remainder of the integer division(this / d), rounded towards -∞.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
fdivq2ExpAssign
public MPZ fdivq2ExpAssign(MPZ n, long b)
Set thisMPZto the quotient of the integer division(n / 2b), rounded toward -∞.- Returns:
- this
MPZ.
-
fdivq2ExpAssign
public MPZ fdivq2ExpAssign(long b)
Set thisMPZto the quotient of the integer division(this / 2b), rounded toward -∞.- Returns:
- this
MPZ.
-
fdivr2ExpAssign
public MPZ fdivr2ExpAssign(MPZ n, long b)
Set thisMPZto the remainder of the integer division(n / 2b), rounded toward -∞.- Returns:
- this
MPZ.
-
fdivr2ExpAssign
public MPZ fdivr2ExpAssign(long b)
Set thisMPZto the remainder of the integer division(this / 2b), rounded toward -∞.- Returns:
- this
MPZ.
-
fdivq
public MPZ fdivq(MPZ d)
Return anMPZwhose value is the quotient of the integer division(this / d), rounded towards -∞.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
fdivr
public MPZ fdivr(MPZ d)
Return anMPZwhose value is the remainder of the integer division(this / d), rounded towards -∞.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
fdivqr
public org.javatuples.Pair<MPZ,MPZ> fdivqr(MPZ d)
Return twoMPZs whose values are the quotient and remainder of the integer division(this / d), rounded towards -∞.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
fdivq2Exp
public MPZ fdivq2Exp(long b)
Return anMPZwhose value is the quotient of the integer division(this / 2b), rounded towards -∞.
-
fdivr2Exp
public MPZ fdivr2Exp(long b)
Return anMPZwhose value is the remainder of the integer division(this / 2b), rounded towards -∞.
-
tdivqAssign
public MPZ tdivqAssign(MPZ n, MPZ d)
Set thisMPZto the quotient of the integer division(n / d), rounded towards zero.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
tdivqAssign
public MPZ tdivqAssign(MPZ d)
Set thisMPZto the quotient of the integer division(this / d), rounded towards zero.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
tdivrAssign
public MPZ tdivrAssign(MPZ n, MPZ d)
Set thisMPZto the remainder of the integer division(n / d), rounded towards zero.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
tdivrAssign
public MPZ tdivrAssign(MPZ d)
Set thisMPZto the remainder of the integer division(this / d), rounded towards zero.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
tdivqrAssign
public MPZ tdivqrAssign(MPZ r, MPZ n, MPZ d)
Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards zero.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.java.lang.IllegalArgumentException- ifthisandrare the same object.
-
tdivqrAssign
public MPZ tdivqrAssign(MPZ r, MPZ d)
Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards zero.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.java.lang.IllegalArgumentException- ifthisandrare the same object.
-
tdivqUiAssign
public long tdivqUiAssign(MPZ n, long d)
Set thisMPZto the quotient of the integer division(n / d), rounded towards zero; it also returns the absolute value of the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
tdivqUiAssign
public long tdivqUiAssign(long d)
Set thisMPZto the quotient of the integer division(this / d), rounded towards zero; it also returns the absolute value of the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
tdivrUiAssign
public long tdivrUiAssign(MPZ n, long d)
Set thisMPZto the remainder of the integer division(n / d), rounded towards zero; it also returns the absolute value of the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
tdivrUiAssign
public long tdivrUiAssign(long d)
Set thisMPZto the remainder of the integer division(this / d), rounded towards zero; it also returns the absolute value of the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
tdivqrUiAssign
public long tdivqrUiAssign(MPZ r, MPZ n, long d)
Set thisMPZandrto the quotient and remainder of the integer division(n / d), rounded towards zero; it also returns the absolute value of the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.java.lang.IllegalArgumentException- ifthisandrare the same object.
-
tdivqrUiAssign
public long tdivqrUiAssign(MPZ r, long d)
Set thisMPZandrto the quotient and remainder of the integer division(this / d), rounded towards zero; it also returns the absolute value of the remainder.- Throws:
java.lang.ArithmeticException- ifdis zero.java.lang.IllegalArgumentException- ifthisandrare the same object.
-
tdivUi
public long tdivUi(long d)
Return the remainder of the integer division(this / d), rounded towards zero.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
tdivq2ExpAssign
public MPZ tdivq2ExpAssign(MPZ n, long b)
Set thisMPZto the quotient of the integer division(n / 2b), rounded toward zero.- Returns:
- this
MPZ.
-
tdivq2ExpAssign
public MPZ tdivq2ExpAssign(long b)
Set thisMPZto the quotient of the integer division(this / 2b), rounded toward zero.- Returns:
- this
MPZ.
-
tdivr2ExpAssign
public MPZ tdivr2ExpAssign(MPZ n, long b)
Set thisMPZto the remainder of the integer division(n / 2b), rounded toward zero.- Returns:
- this
MPZ.
-
tdivr2ExpAssign
public MPZ tdivr2ExpAssign(long b)
Set thisMPZto the remainder of the integer division(this / 2b), rounded toward zero.- Returns:
- this
MPZ.
-
tdivq
public MPZ tdivq(MPZ d)
Return anMPZwhose value is the quotient of the integer division(this / d), rounded towards zero.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
tdivr
public MPZ tdivr(MPZ d)
Return anMPZwhose value is the remainder of the integer division(this / d), rounded towards zero.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
tdivqr
public org.javatuples.Pair<MPZ,MPZ> tdivqr(MPZ d)
Return twoMPZs whose values are the quotient and remainder of the integer division(this / d), rounded towards zero.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
tdivq2Exp
public MPZ tdivq2Exp(long b)
Return anMPZwhose value is the quotient of the integer division(this / 2b), rounded towards zero.
-
tdivr2Exp
public MPZ tdivr2Exp(long b)
Return anMPZwhose value is the remainder of the integer division(this / 2b), rounded towards zero.
-
modAssign
public MPZ modAssign(MPZ n, MPZ d)
Set thisMPZto(n mod d). The sign of the divisor is ignored, the result is always non-negative.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
modAssign
public MPZ modAssign(MPZ d)
Set thisMPZto(this mod d). The sign of the divisor is ignored, the result is always non-negative.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
mod
public MPZ mod(MPZ d)
Return anMPZwhose 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 thisMPZto(n mod d); it also returns the result. The sign of the divisor is ignored, the result is always non-negative.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
modUiAssign
public long modUiAssign(long d)
Set thisMPZto(n mod d); it also returns the result. The sign of the divisor is ignored, the result is always non-negative.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
modUi
public long modUi(long d)
Return anMPZwhose value is(this mod d). The sign of the divisor is ignored, the result is always non-negative.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
divexactAssign
public MPZ divexactAssign(MPZ n, MPZ d)
Set thisMPZto the quotient of(n / d). This method produces correct results only when it is known in advance thatddividesn.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
divexactAssign
public MPZ divexactAssign(MPZ d)
Set thisMPZto the quotient of(this / d). This method produces correct results only when it is known in advance thatddividesthis.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
divexact
public MPZ divexact(MPZ d)
Return anMPZwhose value is the quotient of(this / d). This method produces correct results only when it is known in advance thatddividesthis.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
divexactUiAssign
public MPZ divexactUiAssign(MPZ n, long d)
Set thisMPZto the quotient of(n / d). This method produces correct results only when it is known in advance thatddividesn.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
divexactUiAssign
public MPZ divexactUiAssign(long d)
Set thisMPZto the quotient of(this / d). This method produces correct results only when it is known in advance thatddividesthis.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifdis zero.
-
divexactUi
public MPZ divexactUi(long d)
Return anMPZwhose value is the quotient of(this / d). This method produces correct results only when it is known in advance thatddividesthis.- Throws:
java.lang.ArithmeticException- ifdis zero.
-
isDivisible
public boolean isDivisible(MPZ d)
Returntrueif and only ifthisis exactly divisible byd. This means that there exists an integerqsatisfying(n = q*d). Unlike the other division functions, the cased=0is accepted and following the rule it can be seen that only0is considered divisible by0.
-
isDivisibleUi
public boolean isDivisibleUi(long d)
Returntrueif and only ifthisis exactly divisible byd. This means that there exists an integerqsatisfying(n = q*d). The cased=0is accepted and following the rule it can be seen that only0is considered divisible by0.
-
isDivisible2Exp
public boolean isDivisible2Exp(long b)
Returntrueif and only ifthisis exactly divisible by2b. This means that there exists an integerqsatisfying(n = q * 2^b).
-
isCongruent
public boolean isCongruent(MPZ c, MPZ d)
Returntrueif and only ifthisis congruent tocmodulod. This means that there exists an integerqsatisfying(n = c + q*d). Unlike the other division functions,d=0is accepted and following the rule it can be seen thatnandcare considered congruent modulo0only when exactly equal.
-
isCongruentUi
public boolean isCongruentUi(long c, long d)Returntrueif and only ifthisis congruent tocmodulod. This means that there exists an integerqsatisfying(n = c + q*d). Unlike the other division functions,d=0is accepted and following the rule it can be seen thatnandcare considered congruent modulo0only when exactly equal.
-
isCongruent2Exp
public boolean isCongruent2Exp(MPZ c, long b)
Returntrueif and only ifthisis congruent tocmodulo2b. This means that there exists an integerqsatisfying(n = c + q*2^b).
-
powmAssign
public MPZ powmAssign(MPZ base, MPZ exp, MPZ mod)
Set thisMPZto(baseexp)modulomod. Negativeexpis supported if the inverse ofbasemodulomodexists, otherwise anArithmeticExpectionis thrown.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifmodis zero orbasehas no inverse modulomod.
-
powmAssign
public MPZ powmAssign(MPZ exp, MPZ mod)
Set thisMPZto(thisexp)modulomod.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifmodis zero.
-
powmUiAssign
public MPZ powmUiAssign(MPZ base, long exp, MPZ mod)
Set thisMPZto(baseexp)modulomod.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifmodis zero.
-
powmUiAssign
public MPZ powmUiAssign(long exp, MPZ mod)
Set thisMPZto(thisexp)modulomod.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifmodis zero.
-
powmSecAssign
public MPZ powmSecAssign(MPZ base, MPZ exp, MPZ mod)
Set thisMPZto(baseexp)modulomod. It is required that(exp > 0and thatmodis odd. This function is intended for cryptographic purposes, where resilience to side-channel attacks is desired.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifmodis even orexpis negative.
-
powmSecAssign
public MPZ powmSecAssign(MPZ exp, MPZ mod)
Set thisMPZto(thisexp)modulomod. It is required that(exp > 0and thatmodis odd. This function is intended for cryptographic purposes, where resilience to side-channel attacks is desired.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifmodis zero.
-
powmSec
public MPZ powmSec(MPZ exp, MPZ mod)
Return anMPZwhose value is(thisexp)modulomod. It is required that(exp > 0)and thatmodis 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 thisMPZto(baseexp). The case00yields1.- Returns:
- this
MPZ.
-
powUiAssign
public MPZ powUiAssign(long exp)
Set thisMPZto(thisexp). The case00yields1.- Returns:
- this
MPZ.
-
powUi
public MPZ powUi(long exp)
Return anMPZwhose value is(thisexp). The case00yields1.
-
powUiAssign
public MPZ powUiAssign(long base, long exp)
Set thisMPZto(baseexp). The case00yields1.- Returns:
- this
MPZ.
-
powUi
public static MPZ powUi(long base, long exp)
Return anMPZwhose value is(baseexp). The case00yields1.
-
rootAssign
public boolean rootAssign(MPZ op, long n)
Set thisMPZto the truncated integer part of thenth root ofop.- Returns:
- true if the computation is exact.
- Throws:
java.lang.ArithmeticException- if n is even and op is negative.
-
rootAssign
public boolean rootAssign(long n)
Set thisMPZto the truncated integer part of itsnth root.- Returns:
- true if the computation is exact.
- Throws:
java.lang.ArithmeticException- if n is even and this is negative.
-
root
public org.javatuples.Pair<java.lang.Boolean,MPZ> root(long n)
Return anMPZwhose value is the truncated integer part of thenth root ofthis, and a boolean flag which is true when the result is exact.- Throws:
java.lang.ArithmeticException- if n is even and this is negative.
-
rootremAssign
public MPZ rootremAssign(MPZ rem, MPZ u, long n)
Set thisMPZto the truncated integer part of thenth root ofuandremto the remainder, i.e.,(u - rootn).- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- if n is even and u is negative.
-
rootremAssign
public MPZ rootremAssign(MPZ rem, long n)
Set thisMPZto the truncated integer part of the itsnth root andremto the remainder, i.e.,(this - rootn).- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- if n is even and this is negative.
-
rootrem
public org.javatuples.Pair<MPZ,MPZ> rootrem(long n)
Return twoMPZs whose values are the truncated integer part of thenth root ofthisand the remainder, i.e.,(u - rootn).- Throws:
java.lang.ArithmeticException- if n is even and this is negative.
-
sqrtAssign
public MPZ sqrtAssign(MPZ op)
Set thisMPZto the truncated integer part of the square root ofop.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- if op is negative.
-
sqrtAssign
public MPZ sqrtAssign()
Set thisMPZto the truncated integer part of its square root.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- if this is negative.
-
sqrt
public MPZ sqrt()
Return anMPZwhose value is the truncated integer part of the square root ofthis.- Throws:
java.lang.ArithmeticException- if this is negative.
-
sqrtremAssign
public MPZ sqrtremAssign(MPZ rem, MPZ op)
Set thisMPZto the truncated integer part of the square root ofopandremto the remainder, i.e.,(op - root2).- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- if op is negative.
-
sqrtremAssign
public MPZ sqrtremAssign(MPZ rem)
Set thisMPZto the truncated integer part of its square root andremto the remainder, i.e.,(this - root2).- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- if this is negative.
-
sqrtrem
public org.javatuples.Pair<MPZ,MPZ> sqrtrem()
Return twoMPZs whose values are the truncated integer part of the square root ofthisand the remainder, i.e.,(op - root2).- Throws:
java.lang.ArithmeticException- if this is negative.
-
isPerfectPower
public boolean isPerfectPower()
Returntrueif and only if this number is a perfect power, i.e., if there exist integersaandb, with(b > 1), such thatthisequals(ab). Under this definition both0and1are considered to be perfect powers. Negative values are accepted, but of course can only be odd perfect powers.
-
isPerfectSquare
public boolean isPerfectSquare()
Returntrueif and only if this number is a perfect square. Under this definition both0and1are considered to be perfect squares.
-
isProbabPrime
public MPZ.PrimalityStatus isProbabPrime(int reps)
- Parameters:
reps- can be used to tune the probability of a non-prime being identified as “probably prime”. Reasonable values of reps are between 15 and 50.- Returns:
- an instance of the
MPZ.PrimalityStatusenum, telling whetherthisis definitely prime, probably prime or definitely non-prime.
-
nextprimeAssign
public MPZ nextprimeAssign(MPZ op)
Set thisMPZto the next prime greater thenop. This function uses a probabilistic algorithm to identify primes. For practical purposes it’s adequate, the chance of a composite passing will be extremely small.
-
nextprimeAssign
public MPZ nextprimeAssign()
Set thisMPZto the next prime greater then itself. This function uses a probabilistic algorithm to identify primes. For practical purposes it’s adequate, the chance of a composite passing will be extremely small.
-
nextprime
public MPZ nextprime()
Return anMPZwhose value is the next prime greater thenthis.- See Also:
nextprimeAssign(it.unich.jgmp.MPZ)
-
gcdAssign
public MPZ gcdAssign(MPZ op1, MPZ op2)
Set thisMPZto the greatest commond divisor ofop1andop2. The result is always positive even if one or both input operands are negative. Except if both inputs are zero; then this function definesgcd(0,0) = 0.
-
gcdAssign
public MPZ gcdAssign(MPZ op)
Set thisMPZto the greatest commond divisor ofthisandop. The result is always positive even if one or both operands are negative. Except if boththisandopare zero; then this function Return zero.
-
gcd
public MPZ gcd(MPZ op)
Return anMPZwhose value is the greatest commond divisor ofthisandop.
-
gcdUiAssign
public long gcdUiAssign(MPZ op1, long op2)
Set thisMPZto the greatest commond divisor ofop1andop2, and return it. If the result does not fit into an unsigned long, then 0 si returned.
-
gcdUiAssign
public long gcdUiAssign(long op)
Set thisMPZto the greatest commond divisor ofop1andop2, and returns it. If the result does not fit into an unsigned long, then 0 si returned.
-
gcdUi
public long gcdUi(long op)
Return the greatest commond divisor ofthisandop. If the result does not fit into an unsigned long, 0 is returned.
-
gcdextAssign
public MPZ gcdextAssign(MPZ s, MPZ t, MPZ a, MPZ b)
Set thisMPZto the greatest common divisor ofaandb, and in addition Setsandtto coefficients satisfying(a*s + b*t = gcd). Ifsortis null, that value is not computed. See the GMP functionmpz_gcdext.
-
gcdextAssign
public MPZ gcdextAssign(MPZ s, MPZ t, MPZ op)
Set thisMPZto the greatest common divisor ofthisandop, and in addition Setsandtto coefficients satisfying(this*s + op*t = gcd). Ifsortis null, that value is not computed. See the GMP functionmpz_gcdext.
-
gcdext
public org.javatuples.Triplet<MPZ,MPZ,MPZ> gcdext(MPZ op)
Return the greatest common divisor ofthisandop, together with numberssandtsatisfying(a*this + b*op = g)See the GMP functionmpz_gcdext.
-
lcmAssign
public MPZ lcmAssign(MPZ op1, MPZ op2)
Set thisMPZto the least common multiple ofop1andop2. The result is always non-negative even if one or both input operands are negative. The result will be zero if eitherop1orop2is zero.
-
lcmAssign
public MPZ lcmAssign(MPZ op)
Set thisMPZto the least common multiple ofthisandop. The result is always non-negative even if one or both input operands are negative. The result will be zero if eitherthisoropis zero.
-
lcmUiAssign
public MPZ lcmUiAssign(MPZ op1, long op2)
Set thisMPZto the least common multiple ofop1andop2.
-
lcmUiAssign
public MPZ lcmUiAssign(long op)
Set thisMPZto the least common multiple ofthisandop.
-
lcmUi
public MPZ lcmUi(long op)
Return the least common multiple ofthisandop.
-
invertAssign
public boolean invertAssign(MPZ op1, MPZ op2)
Set thisMPZto the inverse ofop1moduloop2. If the inverse does not exist, the new value of thisMPZis undefined.- Returns:
- true if the inverse exists, false otherwise.
-
invertAssign
public boolean invertAssign(MPZ op)
Set thisMPZto the inverse ofthismoduloop. If the inverse does not exist, the new value of thisMPZis undefined.- Returns:
- true if the inverse exists, false otherwise.
-
invert
public java.util.Optional<MPZ> invert(MPZ op)
Optionally return, when it exists, anMPZwhose value is the inverse ofthismoduloop.
-
jacobi
public int jacobi(MPZ b)
Return the Jacobi symbol(this / b). This is defined only forbodd.
-
legendre
public int legendre(MPZ p)
Return the Legendre symbol(this / p). This is defined only forpan odd positive prime, and for suchpit’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)whenthisis odd, or(this/2)=0whenthisis even. Whenbis odd the Jacobi symbol and Kronecker symbol are identical. See the GMP functionmpz_kronecker.
-
kronecker
public int kronecker(long b)
Return the Jacobi symbol(this / b)with the Kronecker extension.- See Also:
kronecker(it.unich.jgmp.MPZ)
-
kroneckerUi
public int kroneckerUi(long b)
Return the Jacobi symbol(this / b)with the Kronecker extension.- See Also:
kronecker(it.unich.jgmp.MPZ)
-
kroneckerReverse
public int kroneckerReverse(long a)
Return the Jacobi symbol(a / this)with the Kronecker extension.- See Also:
kronecker(it.unich.jgmp.MPZ)
-
uiKronecker
public int uiKronecker(long a)
Return the Jacobi symbol(a / this)with the Kronecker extension.- See Also:
kronecker(it.unich.jgmp.MPZ)
-
removeAssign
public long removeAssign(MPZ op, MPZ f)
Remove all occurrences of the factorffromopand stores the result in thisMPZ. The return value is the number of occurrences offwhich were removed.
-
removeAssign
public long removeAssign(MPZ f)
Remove all occurrences of the factorffromthisMPZ. The return value is the number of occurrences offwhich were removed.
-
remove
public org.javatuples.Pair<java.lang.Long,MPZ> remove(MPZ f)
Return the result of removing the factorffromthis, together with the number of occurrences which were removed.
-
facUiAssign
public MPZ facUiAssign(long n)
Set thisMPZto the factorial ofn.
-
facUi
public static MPZ facUi(long n)
Return anMPZwhose value is the factorial ofn.
-
dfacUiAssign
public MPZ dfacUiAssign(long n)
Set thisMPZto the double factorial ofn.
-
dfacUi
public static MPZ dfacUi(long n)
Return anMPZwhose value the double factorial ofn.
-
mfacUiUiAssign
public MPZ mfacUiUiAssign(long n, long m)
Set thisMPZto them-multi factorial ofn.
-
mfacUiUi
public static MPZ mfacUiUi(long n, long m)
Return anMPZwhose value is them-multi factorial ofn.
-
primorialUiAssign
public MPZ primorialUiAssign(long n)
Set thisMPZto the primorial ofn, i.e., the product of all positive prime numbers<= n.
-
primorialUi
public static MPZ primorialUi(long n)
Return anMPZwhose value is the primorial ofn, i.e., the product of all positive prime numbers<= n.
-
binUiAssign
public MPZ binUiAssign(MPZ n, long k)
Set thisMPZto the binomial coefficientnoverk. Negative values ofnare 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 thisMPZto the binomial coefficientthisoverk. Negative values ofthisare supported using the identity(bin(-n,k) = (-1)^k * bin(n+k-1,k)), see Knuth volume 1 section 1.2.6 part G.
-
binUi
public MPZ binUi(long k)
Return anMPZwhose value is the binomial coefficientthisoverk. Negative values ofthisare supported as inbinUiAssign(it.unich.jgmp.MPZ,long).
-
binUiUiAssign
public MPZ binUiUiAssign(long n, long k)
Set thisMPZto the binomial coefficientnoverk.
-
binUiUi
public static MPZ binUiUi(long n, long k)
Return anMPZwhose value is the binomial coefficientnoverk.
-
fibUiAssign
public MPZ fibUiAssign(long n)
Set thisMPZto then-th Fibonacci number.
-
fibUi
public static MPZ fibUi(long n)
Return anMPZwhose value is then-th Fibonacci number.
-
fib2UiAssign
public MPZ fib2UiAssign(MPZ fnsub1, long n)
Set the value ofthisandfnsub1to then-th and(n-1)-th Fibonacci numbers respecively.
-
fib2Ui
public static org.javatuples.Pair<MPZ,MPZ> fib2Ui(long n)
Return twoMPZwhose values are then-th and(n-1)-th Fibonacci numbers.
-
lucnumUiAssign
public MPZ lucnumUiAssign(long n)
Set thisMPZto then-th Lucas number.
-
lucnumUi
public static MPZ lucnumUi(long n)
Return anMPZwhose value is then-th Lucas number.
-
lucnum2UiAssign
public MPZ lucnum2UiAssign(MPZ fnsub1, long n)
Set the value ofthisandfnsub1to then-th and(n-1)-th Lucas numbers respecively.
-
lucnum2Ui
public static org.javatuples.Pair<MPZ,MPZ> lucnum2Ui(long n)
Return twoMPZwhose values are then-th and(n-1)-th Lucas numbers.
-
cmp
public int cmp(MPZ op)
Comparethiswithop. Return a positive value if(this > op), zero ifthis = op, or a negative value ifthis < op.
-
cmp
public int cmp(double op)
Comparethiswithop. Return a positive value if(this > op), zero ifthis = op, or a negative value ifthis < op. The value ofopmay be infinite, but the result is undefined on NaNs.- Throws:
java.lang.ArithmeticException- ifopis a NaN.
-
cmp
public int cmp(long op)
Comparethiswithop. Return a positive value if(this > op), zero ifthis = op, or a negative value ifthis < op.
-
cmpUi
public int cmpUi(long op)
Comparethiswithop. Return a positive value if(this > op), zero ifthis = op, or a negative value ifthis < op.
-
cmpabs
public int cmpabs(MPZ op)
Compare the absolute values ofthisandop. Return a positive value if(abs(this) > abs(op)), zero ifabs(this) = abs(op), or a negative value ifabs(this) < abs(op).
-
cmpabs
public int cmpabs(double op)
Compare the absolute values ofthisandop. Return a positive value if(abs(this) > abs(op)), zero ifabs(this) = abs(op), or a negative value ifabs(this) < abs(op). The value ofopmay be infinite, but the result is undefined on NaNs.- Throws:
java.lang.ArithmeticException- ifopis a NaN.
-
cmpabsUi
public int cmpabsUi(long op)
Compare the absolute values ofthisandop. Return a positive value if(abs(this) > abs(op)), zero ifabs(this) = abs(op), or a negative value ifabs(this) < abs(op).
-
sgn
public int sgn()
Return+1if(this > 0),0if(this = 0)and-1ifthis < 0.
-
comAssign
public MPZ comAssign()
Set thisMPZto(~ this).
-
com
public MPZ com()
Return anMPZwhose value is(~ op).
-
popcount
public long popcount()
If thisMPZis non-negative, return its population count, which is the number of1bits in its binary representation. If thisMPZis negative, the number of1s is infinite, and the return value is the largest possible value for the native typemp_bitcnt_t.
-
hamdist
public long hamdist(MPZ op)
Ifthisandopare both>= 0or both< 0, return the Hamming distance between them, which is the number of bit positions wherethisandophave different bit values. If one operand is>= 0and the other< 0then the number of bits different is infinite, and the return value is the largest possible value for the native typemp_bitcnt_t.
-
scan0
public long scan0(long starting_bit)
Scan thisMPZ, starting from bitstarting_bit, towards more significant bits, until the first0bit is found. Return the index of the found bit.
-
scan1
public long scan1(long starting_bit)
Scanthis, starting from bitstarting_bit, towards more significant bits, until the first1bit is found. Return the index of the found bit.
-
setbitAssign
public MPZ setbitAssign(long index)
Set the bitindexof thisMPZ.
-
setbit
public MPZ setbit(long index)
Return anMPZwhose value is(this | 2index).
-
clrbitAssign
public MPZ clrbitAssign(long index)
Clear the bitindexof thisMPZ.
-
clrbit
public MPZ clrbit(long index)
Return anMPZwhose value is(this & ~ 2index).
-
combitAssign
public MPZ combitAssign(long index)
Complement the bitindexof thisMPZ.
-
combit
public MPZ combit(long index)
Return anMPZwhose value is(this ^ 2index).
-
tstbit
public int tstbit(long index)
Return the bitindexof thisMPZ.
-
urandombAssign
public MPZ urandombAssign(RandState s, long n)
Set thisMPZto a uniformly distributed random integer in the range0to(2n - 1), inclusive.
-
urandomb
public static MPZ urandomb(RandState s, long n)
Return anMPZwhose value is an uniformly distributed random integer in the range0} to(2n - 1), inclusive.
-
urandommAssign
public MPZ urandommAssign(RandState s, MPZ n)
Set thisMPZto a uniformly distributed random integer in the range0to(n - 1), inclusive.
-
urandomm
public static MPZ urandomm(RandState s, MPZ n)
Return anMPZwhose value is an uniformly distributed random integer in the range0to(n - 1), inclusive.
-
rrandombAssign
public MPZ rrandombAssign(RandState s, long n)
Set thisMPZto a random integer with long strings of zeros and ones in the binary representation. Useful for testing functions and algorithms, since this kind of random numbers have proven to be more likely to trigger corner-case bugs. The random number will be in the range(2n - 1)to(2n - 1), inclusive.
-
rrandomb
public static MPZ rrandomb(RandState s, long n)
Return anMPZwhose value is a random integer with long strings of zeros and ones in the binary representation. Useful for testing functions and algorithms, since this kind of random numbers have proven to be more likely to trigger corner-case bugs. The random number will be in the range(2n - 1)to(2n - 1), inclusive.
-
randomAssign
@Deprecated public MPZ randomAssign(long max_size)
Deprecated.useurandombAssign(it.unich.jgmp.RandState,long)orurandommAssign(it.unich.jgmp.RandState,it.unich.jgmp.MPZ)instead, since this method uses a global random state and it is not reentrant.Set thisMPZto a random integer of at mostmax_sizelimbs. The generated random number doesn’t satisfy any particular requirements of randomness. Negative random numbers are generated whenmax_sizeis negative.- Returns:
- this
MPZ.
-
random
@Deprecated public static MPZ random(long max_size)
Deprecated.useurandomb(it.unich.jgmp.RandState,long)orurandomm(it.unich.jgmp.RandState,it.unich.jgmp.MPZ)instead, since this method uses a global random state and it is not reentrant.Return anMPZwhose value is a random integer of at mostmax_sizelimbs. The generated random number doesn’t satisfy any particular requirements of randomness. Negative random numbers are generated whenmax_sizeis negative.
-
random2Assign
@Deprecated public MPZ random2Assign(long max_size)
Deprecated.userrandombAssign(it.unich.jgmp.RandState,long)instead, since this method uses a global random state and it is not reentrant.Set thisMPZto a random integer of at mostmax_sizelimbs, with long strings of zeros and ones in the binary representation. Useful for testing functions and algorithms, since this kind of random numbers have proven to be more likely to trigger corner-case bugs. Negative random numbers are generated whenmax_sizeis negative.- Returns:
- this
MPZ.
-
random2
@Deprecated public static MPZ random2(long max_size)
Deprecated.userrandomb(it.unich.jgmp.RandState,long)instead, since this method uses a global random state and it is not reentrant.Return anMPZwhose value is a random integer of at mostmax_sizelimbs, with long strings of zeros and ones in the binary representation. Useful for testing functions and algorithms, since this kind of random numbers have proven to be more likely to trigger corner-case bugs. Negative random numbers are generated whenmax_sizeis negative.
-
bufferImportAssign
public MPZ bufferImportAssign(int order, int size, int endian, long nails, java.nio.ByteBuffer op)
Set thisMPZfrom the buffer of word data atop. See the detailed description in the documentation of the GMP functionmpz_import. The parametercountin the prototype ofmpz_importis automatically computed by the capacity of the bufferop. Thesizeparameter is declared asintinstead oflongsince Java does not allow byte buffers to be longer than 4GB.
-
bufferImport
public static MPZ bufferImport(int order, int size, int endian, long nails, java.nio.ByteBuffer op)
Return anMPZwhose value is determined from the buffer of word data atop. Thesizeparameter is declared asintinstead oflongsince Java does not allow byte buffers to be longer than 4GB.
-
bufferExport
public java.nio.ByteBuffer bufferExport(int order, int size, int endian, long nails)Return aByteBufferfilled with word data from thisMPZ. See the detailed description in the documentation of the GMP functionmpz_export. We let the function allocate the buffer, since it the easier and safer. The outputcountof the original GMP function is not needed, since it corresponds to the capacity of the resultingByteBuffer. Thesizeparameter is declared asintinstead oflongsince Java does not allow byte buffers to be longer than 4GB.
-
fitsUlong
public boolean fitsUlong()
Returntrueif and only if thisMPZfits into a native unsigned long.
-
fitsSlong
public boolean fitsSlong()
Returntrueif and only if thisMPZfits into a native signed long.
-
fitsUint
public boolean fitsUint()
Returntrueif and only if thisMPZfits into a native unsigned int.
-
fitsSint
public boolean fitsSint()
Returntrueif and only if thisMPZfits into a native signed int.
-
fitsUshort
public boolean fitsUshort()
Returntrueif and only if thisMPZfits into a native unsigned short.
-
fitsSshort
public boolean fitsSshort()
Returntrueif and only if thisMPZfits into a native signed short.
-
isOdd
public boolean isOdd()
Returntrueif and only if thisMPZis odd.
-
isEven
public boolean isEven()
Returntrueif and only if thisMPZis even
-
isZero
public boolean isZero()
Returntrueif and only if thisMPZis zero.
-
sizeinbase
public long sizeinbase(int base)
Return the size of thisMPZmeasured in number of digits in the specifiedbase. See the the GMP functionmpz_sizeinbase.- Throws:
java.lang.IllegalArgumentException- if base is not between 2 and 62.
-
setValue
public MPZ setValue(long op)
Set thisMPZto signed longop.- Returns:
- this
MPZ.
-
setValue
public MPZ setValue(double op)
Set thisMPZto the truncation opop.- Returns:
- this
MPZ. - Throws:
java.lang.ArithmeticException- ifopis not a finite number. In this case,thisis not altered.
-
setValue
public MPZ setValue(java.lang.String str, int base)
Set thisMPZto the number represented by the stringstrin the specifiedbase. See the GMP functionmpz_set_str.- Throws:
java.lang.NumberFormatException- if eitherbaseis not valid orstris not a valid number representation in the specified base. In this case,thisis not altered.
-
setValue
public MPZ setValue(java.lang.String str)
Set thisMPZto the value represented by the stringstrin decimal base.- Throws:
java.lang.NumberFormatException- ifstris not a valid number representation in decimal base.- See Also:
setValue(java.lang.String,int)
-
setValue
public MPZ setValue(java.math.BigInteger op)
Sets thisMPZtoop.- Returns:
- this
MPZ.
-
compareTo
public int compareTo(MPZ op)
Compare thisMPZwithop. Return a positive value if(this > op), zero ifthis = op, or a negative value ifthis < op. This order is compatible with equality.- Specified by:
compareToin interfacejava.lang.Comparable<MPZ>
-
equals
public boolean equals(java.lang.Object obj)
Compare thisMPZwith the objectopfor equality. It returnstrueif and only ifopis anMPZwith the same value ofthis.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Return a hash code value for thisMPZ.- Overrides:
hashCodein classjava.lang.Object
-
longValue
public long longValue()
Convert thisMPZto a signed long. If this number is too big to fit a native signed long, return the least significant part, preserving the sign.- Specified by:
longValuein classjava.lang.Number
-
intValue
public int intValue()
Convert thisMPZto a signed int, truncating if necessary.- Specified by:
intValuein classjava.lang.Number
-
doubleValue
public double doubleValue()
Convert thisMPZto a double, truncating if necessary. If the exponent from the conversion is too big, the result is system dependent. An infinity is returned where available. A hardware overflow trap may or may not occur.- Specified by:
doubleValuein classjava.lang.Number
-
floatValue
public float floatValue()
Convert thisMPZto a float, truncating if necessary.- Specified by:
floatValuein classjava.lang.Number
-
toString
public java.lang.String toString(int base)
Convert thisMPZto its string representation in the specifiedbase, ornullif the base is not valid. See the GMP functionmpz_get_str.
-
toString
public java.lang.String toString()
Convert thisMPZto its decimal string representation.- Overrides:
toStringin classjava.lang.Object
-
writeObject
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException- Throws:
java.io.IOException
-
readObject
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
readObjectNoData
private void readObjectNoData() throws java.io.ObjectStreamException- Throws:
java.io.ObjectStreamException
-
-