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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BigIntegerabs(BigInteger a)static BigIntegerbinomial(int n, int k)Binomial coefficientstatic BigIntegerfactorial(int number)Factorial of a numberstatic BigIntegergcd(BigInteger[] integers, int from, int to)Returns the greatest common an array of longsstatic BigIntegergcd(BigInteger a, BigInteger b)static BigIntegermax(BigInteger a, BigInteger b)static BigInteger[]perfectPowerDecomposition(BigInteger n)Tests whethernis a perfect powern == a^band returns{a, b}if so andnullotherwisestatic BigIntegerpow(long base, long exponent)Returnsbasein a power ofe(non negative)static BigIntegerpow(BigInteger base, int exponent)Returnsbasein a power ofe(non negative)static BigIntegerpow(BigInteger base, long exponent)Returnsbasein a power ofe(non negative)static BigIntegerpow(BigInteger base, BigInteger exponent)Returnsbasein a power ofe(non negative)static BigIntegersqrtCeil(BigInteger val)Returns ceil square root ofvalstatic BigIntegersqrtFloor(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)
Returnsbasein a power ofe(non negative)- Parameters:
base- baseexponent- exponent (non negative)- Returns:
basein a power ofe- Throws:
ArithmeticException- if the result overflows a long
-
pow
public static BigInteger pow(BigInteger base, long exponent)
Returnsbasein a power ofe(non negative)- Parameters:
base- baseexponent- exponent (non negative)- Returns:
basein a power ofe- Throws:
ArithmeticException- if the result overflows a long
-
pow
public static BigInteger pow(BigInteger base, int exponent)
Returnsbasein a power ofe(non negative)- Parameters:
base- baseexponent- exponent (non negative)- Returns:
basein a power ofe- Throws:
ArithmeticException- if the result overflows a long
-
pow
public static BigInteger pow(BigInteger base, BigInteger exponent)
Returnsbasein a power ofe(non negative)- Parameters:
base- baseexponent- exponent (non negative)- Returns:
basein 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 whethernis a perfect powern == a^band returns{a, b}if so andnullotherwise- Parameters:
n- the number- Returns:
- array
{a, b}so thatn = a^bornullisnis 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
-
-