A.2 JSLMath Class

The JSLMath class is a singleton similar to java’s Math class that adds some additional mathematical capabilities. Many of the methods provide basic functionality involving arrays. The methods include the following methods.

  • double getDefaultNumericalPrecision() - returns the default numerical precision that can be expected on the machine
  • boolean equal(double a, double b) - returns true if the two doubles are equal with respect to the default numerical precision
  • boolean equal(double a, double b, double precision) - returns true if the two doubles are equal with respect to the specified precision
  • boolean within(double a, double b, double precision) - returns true if the absolute difference between the double is within the specified precision
  • double factorial(int n) - returns a numerically stable computed value of the factorial
  • double binomialCoefficient(int n, int k) - returns a numerically stable computed value of the binomial coefficient
  • double logFactorial(int n) - returns the natural logarithm of the factorial

The following methods work on arrays. While the Statistic class facilitates finding the minimum and maximum of an array of doubles, the JSLMath also provides this capability for long and int arrays.

  • int getIndexOfMin(long[] x)
  • long getMin(long[] x)
  • int getIndexOfMax(long[] x)
  • long getMax(long[] x)
  • int getIndexOfMin(int[] x)
  • int getMin(int[] x)
  • int getIndexOfMax(int[] x)
  • int getMax(int[] x)

JSLMath also provides for basic array manipulation via the following methods.

  • double getRange(double[] array) - the difference between the largest and smallest element of the array.
  • double[] getMinMaxScaledArray(double[] array) - rescales the array based the the range of the array.
  • double[] copyWithout(int index, double[] fromA) - copies all the element of A except that one at element index
  • double[] addConstant(double[] a, double c) - adds a constant to all elements of the array
  • double[] subtractConstant(double[] a, double c) - subtracts a constant from all elements of the array
  • double[] multiplyConstant(double[] a, double c) - multiplies all elements of the array by a constant
  • double[] divideConstant(double[] a, double c)- divides all elements of the array by a constant
  • double[] multiplyElements(double[] a, double[] b) - performs row element multiplication of the arrays
  • double getSumSquares(double[] array) - computes the sum of squares for the array
  • double getSumSquareRoots(double[] array) - computes the sum of the square roots of the elements of the array
  • double[] addElements(double[] a, double[] b) - performs row element addition of the arrays
  • boolean compareArrays(double[] first, double[] second) - returns true if element pairs are all the same in the two arrays.
  • <T> List<T> getElements(List objects, Class<T> targetClass) - finds all elements in the list that are of the same class
  • countElements(List objects, Class targetClass) - counts how many elements in the list are of the same class