Package cc.redberry.rings.bigint
Class BigIntegerUtil
- java.lang.Object
-
- cc.redberry.rings.bigint.BigIntegerUtil
-
public final class BigIntegerUtil extends Object
- Since:
- 1.0
-
-
Method Summary
Modifier and Type Method Description static BigInteger
abs(BigInteger a)
static BigInteger
binomial(int n, int k)
Binomial coefficientstatic BigInteger
factorial(int number)
Factorial of a numberstatic BigInteger
gcd(BigInteger[] integers, int from, int to)
Returns the greatest common an array of longsstatic BigInteger
gcd(BigInteger a, BigInteger b)
static BigInteger
max(BigInteger a, BigInteger b)
static BigInteger[]
perfectPowerDecomposition(BigInteger n)
Tests whethern
is a perfect powern == a^b
and returns{a, b}
if so andnull
otherwisestatic BigInteger
pow(long base, long exponent)
Returnsbase
in a power ofe
(non negative)static BigInteger
pow(BigInteger base, int exponent)
Returnsbase
in a power ofe
(non negative)static BigInteger
pow(BigInteger base, long exponent)
Returnsbase
in a power ofe
(non negative)static BigInteger
pow(BigInteger base, BigInteger exponent)
Returnsbase
in a power ofe
(non negative)static BigInteger
sqrtCeil(BigInteger val)
Returns ceil square root ofval
static BigInteger
sqrtFloor(BigInteger val)
Returns floor square root ofval
-
-
-
Method Detail
-
max
public static BigInteger max(BigInteger a, BigInteger b)
-
abs
public static BigInteger abs(BigInteger a)
-
gcd
public static BigInteger gcd(BigInteger a, BigInteger b)
-
gcd
public static BigInteger gcd(BigInteger[] integers, int from, int to)
Returns the greatest common an array of longs- Parameters:
integers
- array of longsfrom
- from position (inclusive)to
- to position (exclusive)- Returns:
- greatest common divisor of array
-
pow
public static BigInteger pow(long base, long exponent)
Returnsbase
in a power ofe
(non negative)- Parameters:
base
- baseexponent
- exponent (non negative)- Returns:
base
in a power ofe
- Throws:
ArithmeticException
- if the result overflows a long
-
pow
public static BigInteger pow(BigInteger base, long exponent)
Returnsbase
in a power ofe
(non negative)- Parameters:
base
- baseexponent
- exponent (non negative)- Returns:
base
in a power ofe
- Throws:
ArithmeticException
- if the result overflows a long
-
pow
public static BigInteger pow(BigInteger base, int exponent)
Returnsbase
in a power ofe
(non negative)- Parameters:
base
- baseexponent
- exponent (non negative)- Returns:
base
in a power ofe
- Throws:
ArithmeticException
- if the result overflows a long
-
pow
public static BigInteger pow(BigInteger base, BigInteger exponent)
Returnsbase
in a power ofe
(non negative)- Parameters:
base
- baseexponent
- exponent (non negative)- Returns:
base
in a power ofe
- Throws:
ArithmeticException
- if the result overflows a long
-
sqrtFloor
public static BigInteger sqrtFloor(BigInteger val) throws IllegalArgumentException
Returns floor square root ofval
- Parameters:
val
- the number- Returns:
- floor square root
- Throws:
IllegalArgumentException
-
sqrtCeil
public static BigInteger sqrtCeil(BigInteger val) throws IllegalArgumentException
Returns ceil square root ofval
- Parameters:
val
- the number- Returns:
- floor square root
- Throws:
IllegalArgumentException
-
perfectPowerDecomposition
public static BigInteger[] perfectPowerDecomposition(BigInteger n)
Tests whethern
is a perfect powern == a^b
and returns{a, b}
if so andnull
otherwise- Parameters:
n
- the number- Returns:
- array
{a, b}
so thatn = a^b
ornull
isn
is not a perfect power
-
factorial
public static BigInteger factorial(int number)
Factorial of a number
-
binomial
public static BigInteger binomial(int n, int k)
Binomial coefficient
-
-