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