Class MathExt


  • public class MathExt
    extends java.lang.Object
    A util class for some simple mathematical helpers.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long binomial​(int n, int k)
      Computes the binomial of n choose k.
      static int doubleFactorial​(int k)
      Computes the double factorial of k, i.e. k!!.
      static java.util.Set<java.lang.Integer> getIntegersFromTo​(int from, int to)
      Gets a list of all integers for a certain range "from" to "to" (both inclusively).
      static double logBase​(double v, double base)
      Takes the logarithm with respect to some given base.
      static double round​(double d, int precision)
      Rounds a double value to a certain number of decimal places.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • binomial

        public static long binomial​(int n,
                                    int k)
        Computes the binomial of n choose k.
        Parameters:
        n - The size of the whole set.
        k - The size of the chosen subset.
        Returns:
        The number of all possible combinations of how to choose k elements from a set of n elements.
      • getIntegersFromTo

        public static java.util.Set<java.lang.Integer> getIntegersFromTo​(int from,
                                                                         int to)
        Gets a list of all integers for a certain range "from" to "to" (both inclusively).
        Parameters:
        from - The lower bound (included).
        to - The upper bound (included).
        Returns:
        The set of all integers of the specified range.
      • doubleFactorial

        public static int doubleFactorial​(int k)
        Computes the double factorial of k, i.e. k!!.
        Parameters:
        k - The k for which to compute the double factorial for.
        Returns:
        The double factorial for the specified number k.
      • round

        public static double round​(double d,
                                   int precision)
        Rounds a double value to a certain number of decimal places.
        Parameters:
        d - The value to be rounded.
        precision - The number of decimal places.
        Returns:
        The rounded value.
      • logBase

        public static double logBase​(double v,
                                     double base)
        Takes the logarithm with respect to some given base.
        Parameters:
        v - The value to take the logarithm of.
        base - The base of the logarithm.