Class BigFunctions

java.lang.Object
com.compomics.util.math.BigFunctions

public class BigFunctions
extends Object
Functions operating with BigDecimal objects.
Author:
Marc Vaudel
  • Constructor Details

    • BigFunctions

      public BigFunctions()
      Empty default constructor
  • Method Details

    • factorial

      public static BigInteger factorial​(BigInteger n)
      Returns n! as BigInteger.
      Parameters:
      n - a given BigInteger
      Returns:
      the corresponding factorial
    • factorial

      public static BigInteger factorial​(BigInteger n, BigInteger k)
      Returns n!/k! as BigInteger.
      Parameters:
      n - a given BigInteger
      k - a given BigInteger
      Returns:
      the corresponding factorial
    • getCombination

      public static BigInteger getCombination​(BigInteger k, BigInteger n)
      Returns the number of k-combinations in a set of n elements as a big decimal.
      Parameters:
      k - the number of k-combinations
      n - the number of elements
      Returns:
      the number of k-combinations in a set of n elements
    • ln

      public static BigDecimal ln​(BigDecimal bigDecimal, MathContext mathContext)
      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 on
      mathContext - the math context to use for the calculation
      Returns:
      the log of a big decimal
    • lnBD

      public static BigDecimal lnBD​(BigDecimal bigDecimal, MathContext mathContext)
      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 on
      mathContext - the math context to use for the calculation
      Returns:
      the log of a big decimal
    • log

      public static BigDecimal log​(BigDecimal input, double base, MathContext mathContext)
      Returns the log of the input in the desired base. See ln method. Results are not rounded.
      Parameters:
      input - the input
      base - the log base
      mathContext - the math context to use for the calculation
      Returns:
      the log value of the input in the desired base.
    • exp

      public static BigDecimal exp​(BigDecimal bigDecimal, MathContext mathContext)
      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 decimal
      mathContext - the math context
      Returns:
      the value of the exponential of the given BigDecimal using the given MathContext
    • getMaxExp

      public static BigDecimal getMaxExp​(MathContext mathContext)
      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

      public static BigDecimal expBD​(BigDecimal x, MathContext mathContext)
      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 decimal
      mathContext - the math context
      Returns:
      the value of the exponential of the given BigDecimal using the given MathContext
    • pow

      public static BigDecimal pow​(BigDecimal x1, BigDecimal x2, MathContext mathContext)
      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 decimal
      x2 - the second big decimal
      mathContext - the math context
      Returns:
      the first big decimal power the second using the given math context