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 machineboolean equal(double a, double b)
- returns true if the two doubles are equal with respect to the default numerical precisionboolean equal(double a, double b, double precision)
- returns true if the two doubles are equal with respect to the specified precisionboolean within(double a, double b, double precision)
- returns true if the absolute difference between the double is within the specified precisiondouble factorial(int n)
- returns a numerically stable computed value of the factorialdouble binomialCoefficient(int n, int k)
- returns a numerically stable computed value of the binomial coefficientdouble 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 indexdouble[] addConstant(double[] a, double c)
- adds a constant to all elements of the arraydouble[] subtractConstant(double[] a, double c)
- subtracts a constant from all elements of the arraydouble[] multiplyConstant(double[] a, double c)
- multiplies all elements of the array by a constantdouble[] divideConstant(double[] a, double c)
- divides all elements of the array by a constantdouble[] multiplyElements(double[] a, double[] b)
- performs row element multiplication of the arraysdouble getSumSquares(double[] array)
- computes the sum of squares for the arraydouble getSumSquareRoots(double[] array)
- computes the sum of the square roots of the elements of the arraydouble[] addElements(double[] a, double[] b)
- performs row element addition of the arraysboolean 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 classcountElements(List objects, Class targetClass)
- counts how many elements in the list are of the same class