Package com.compomics.util.math
Class BigFunctions
java.lang.Object
com.compomics.util.math.BigFunctions
public class BigFunctions extends Object
Functions operating with BigDecimal objects.
- Author:
- Marc Vaudel
-
Constructor Summary
Constructors Constructor Description BigFunctions()
Empty default constructor -
Method Summary
Modifier and Type Method Description static BigDecimal
exp(BigDecimal bigDecimal, MathContext mathContext)
Returns the value of the exponential of the given BigDecimal using the given MathContext.static BigDecimal
expBD(BigDecimal x, MathContext mathContext)
Returns the value of the exponential of the given BigDecimal using the given MathContext.static BigInteger
factorial(BigInteger n)
Returns n! as BigInteger.static BigInteger
factorial(BigInteger n, BigInteger k)
Returns n!/k! as BigInteger.static BigInteger
getCombination(BigInteger k, BigInteger n)
Returns the number of k-combinations in a set of n elements as a big decimal.static BigDecimal
getMaxExp(MathContext mathContext)
Returns the estimated maximal value exp can be calculated on according to the mathContext.static BigDecimal
ln(BigDecimal bigDecimal, MathContext mathContext)
Returns the natural logarithm of a big decimal.static BigDecimal
lnBD(BigDecimal bigDecimal, MathContext mathContext)
Returns the log of a big decimal.static BigDecimal
log(BigDecimal input, double base, MathContext mathContext)
Returns the log of the input in the desired base.static BigDecimal
pow(BigDecimal x1, BigDecimal x2, MathContext mathContext)
Returns the first big decimal power the second using the given math context.
-
Constructor Details
-
BigFunctions
public BigFunctions()Empty default constructor
-
-
Method Details
-
factorial
Returns n! as BigInteger.- Parameters:
n
- a given BigInteger- Returns:
- the corresponding factorial
-
factorial
Returns n!/k! as BigInteger.- Parameters:
n
- a given BigIntegerk
- a given BigInteger- Returns:
- the corresponding factorial
-
getCombination
Returns the number of k-combinations in a set of n elements as a big decimal.- Parameters:
k
- the number of k-combinationsn
- the number of elements- Returns:
- the number of k-combinations in a set of n elements
-
ln
Returns the natural logarithm of a big decimal. FastMath method is used when possible. Results are not rounded.- Parameters:
bigDecimal
- the big decimal to estimate the log onmathContext
- the math context to use for the calculation- Returns:
- the log of a big decimal
-
lnBD
Returns the log of a big decimal. No FastMath method is used, see ln(). Results are not rounded.- Parameters:
bigDecimal
- the big decimal to estimate the log onmathContext
- the math context to use for the calculation- Returns:
- the log of a big decimal
-
log
Returns the log of the input in the desired base. See ln method. Results are not rounded.- Parameters:
input
- the inputbase
- the log basemathContext
- the math context to use for the calculation- Returns:
- the log value of the input in the desired base.
-
exp
Returns the value of the exponential of the given BigDecimal using the given MathContext. When possible, the FastMath method is used, and no rounding is performed. Results are not rounded.- Parameters:
bigDecimal
- the big decimalmathContext
- the math context- Returns:
- the value of the exponential of the given BigDecimal using the given MathContext
-
getMaxExp
Returns the estimated maximal value exp can be calculated on according to the mathContext. Attempting to calculate exp on higher values (or lower than -value) will most likely overflow the capacity of a BigDecimal. Results are not rounded.- Parameters:
mathContext
- the math context to use for the calculation- Returns:
- the maximal value exp can be calculated on
-
expBD
Returns the value of the exponential of the given BigDecimal using the given MathContext. FastMath method is not used, see exp(). Results are not rounded. The result is of precision p=p0-x.log(e) where p0 is the precision of the math context and log is the log 10. First order, no guarantee.- Parameters:
x
- the big decimalmathContext
- the math context- Returns:
- the value of the exponential of the given BigDecimal using the given MathContext
-
pow
Returns the first big decimal power the second using the given math context. Results are not rounded. The precision of the result is p=p0-x2.ln(x1).log(e)-log(ln(x1)+x2) where p0 is the precision of the math context and log is the log 10. First order, no guarantee. If x1 is exact, e.g. in 10^x2, p=p0-x2.ln(x1).log(e)-log(ln(x1)) where p0 is the precision of the math context and log is the log 10. First order, no guarantee.- Parameters:
x1
- the first big decimalx2
- the second big decimalmathContext
- the math context- Returns:
- the first big decimal power the second using the given math context
-