Class MathUtils
java.lang.Object
org.episteme.core.mathematics.util.MathUtils
The extra math library.
Provides extra functions not in java.lang.Math class.
This class cannot be subclassed or instantiated because all methods are static.
- Version:
- 1.2
- Author:
- Mark Hale
-
Method Summary
Modifier and TypeMethodDescriptionstatic doubleacosh(double x) Returns the inverse hyperbolic cosine of a double.static doubleasinh(double x) Returns the inverse hyperbolic sine of a double.static doubleatanh(double x) Returns the inverse hyperbolic tangent of a double.static doublebinomial(double n, double k) Returns the binomial coefficient (n k).static intbinomial(int n, int k) Returns the binomial coefficient (n k).static doublecosh(double x) Returns the hyperbolic cosine of a double.static doublefactorial(double x) Returns the factorial.static intGCD(int a, int b) Returns the Greatest Common Divisor (GCD).static doublehypot(double x, double y) Returns sqrt(x2+y2).static intLCM(int a, int b) Returns the Least Common Multiple (LCM).static doublelog10(double x) Returns the base 10 logarithm of a double.static doublelog2(double d) Returns the base 2 logarithm of a double.static doublelogB(double d, double d1) Returns the logarithm of a double in a given base.static doublelogFactorial(double x) Returns the natural logarithm of the factorial.static doublemaxOf3(double a, double b, double c) Returns the maximum of three double values.static doublemidOf3(double a, double b, double c) Returns the middle of three double values.static doubleminOf3(double a, double b, double c) Returns the minimum of three double values.static double[]pascalTriangle(int n) Returns the n-th row of Pascal's triangle.static doublepolynomialExpansion(double n, double[] k) Returns the multinomial coefficient (n k[]).static intpow(int a, int b) Returns ab.static intpow2(int a) Returns 2a.static doubleround(double x, int significant) Rounds a number to so many significant figures.static doublesigmoid(double x) Produces a double between 0 and 1 using the sigmoid function.static doublesigmoid(double x, double flatteningFactor) Produces a double between 0 and 1 using a flattened sigmoid function.static intsign(double x) Returns the signum of a double.static doublesinh(double x) Returns the hyperbolic sine of a double.static intsumOfDigits(long number) Returns the sum of all individual digits of a number.static doubletanh(double x) Returns the hyperbolic tangent of a double.
-
Method Details
-
round
public static double round(double x, int significant) Rounds a number to so many significant figures.- Parameters:
x- a number to be rounded.significant- number of significant figures to round to.- Returns:
- the rounded number
-
hypot
public static double hypot(double x, double y) Returns sqrt(x2+y2).- Parameters:
x- a doubley- a double- Returns:
- the hypotenuse
- See Also:
-
pow
public static int pow(int a, int b) Returns ab.- Parameters:
a- an integer.b- a positive integer.- Returns:
- a^b
-
pow2
public static int pow2(int a) Returns 2a.- Parameters:
a- a positive integer.- Returns:
- 2^a
-
factorial
public static double factorial(double x) Returns the factorial. (Wrapper for the gamma function).- Parameters:
x- a double.- Returns:
- x!
- See Also:
-
logFactorial
public static double logFactorial(double x) Returns the natural logarithm of the factorial. (Wrapper for the log gamma function).- Parameters:
x- a double.- Returns:
- ln(x!)
- See Also:
-
binomial
public static int binomial(int n, int k) Returns the binomial coefficient (n k). Uses Pascal's recursion formula.- Parameters:
n- an integer.k- an integer.- Returns:
- (n k)
-
binomial
public static double binomial(double n, double k) Returns the binomial coefficient (n k). Uses gamma functions.- Parameters:
n- a double.k- a double between 0 and n.- Returns:
- (n k)
-
polynomialExpansion
public static double polynomialExpansion(double n, double[] k) Returns the multinomial coefficient (n k[]). Uses gamma functions.- Parameters:
n- a double.k- a double array such that k1 + k2 + k3 + ... + km = n (unchecked).- Returns:
- the multinomial coefficient
-
GCD
public static int GCD(int a, int b) Returns the Greatest Common Divisor (GCD).- Parameters:
a- the first integer.b- the second integer.- Returns:
- the GCD.
-
LCM
public static int LCM(int a, int b) Returns the Least Common Multiple (LCM).- Parameters:
a- the first integer.b- the second integer.- Returns:
- the LCM.
-
log10
public static double log10(double x) Returns the base 10 logarithm of a double.- Parameters:
x- a double.- Returns:
- log10(x)
-
logB
public static double logB(double d, double d1) Returns the logarithm of a double in a given base.- Parameters:
d- the valued1- the base- Returns:
- log_d1(d)
-
log2
public static double log2(double d) Returns the base 2 logarithm of a double.- Parameters:
d- the value- Returns:
- log2(d)
-
sinh
public static double sinh(double x) Returns the hyperbolic sine of a double.- Parameters:
x- a double.- Returns:
- sinh(x)
- See Also:
-
cosh
public static double cosh(double x) Returns the hyperbolic cosine of a double.- Parameters:
x- a double.- Returns:
- cosh(x)
- See Also:
-
tanh
public static double tanh(double x) Returns the hyperbolic tangent of a double.- Parameters:
x- a double.- Returns:
- tanh(x)
- See Also:
-
asinh
public static double asinh(double x) Returns the inverse hyperbolic sine of a double.- Parameters:
x- a double.- Returns:
- asinh(x)
-
acosh
public static double acosh(double x) Returns the inverse hyperbolic cosine of a double.- Parameters:
x- a double.- Returns:
- acosh(x)
-
atanh
public static double atanh(double x) Returns the inverse hyperbolic tangent of a double.- Parameters:
x- a double.- Returns:
- atanh(x)
-
sign
public static int sign(double x) Returns the signum of a double.- Parameters:
x- the double- Returns:
- the signum
-
maxOf3
public static double maxOf3(double a, double b, double c) Returns the maximum of three double values.- Parameters:
a- first valueb- second valuec- third value- Returns:
- max(a, b, c)
-
midOf3
public static double midOf3(double a, double b, double c) Returns the middle of three double values.- Parameters:
a- first valueb- second valuec- third value- Returns:
- the middle value
-
minOf3
public static double minOf3(double a, double b, double c) Returns the minimum of three double values.- Parameters:
a- first valueb- second valuec- third value- Returns:
- min(a, b, c)
-
sigmoid
public static double sigmoid(double x) Produces a double between 0 and 1 using the sigmoid function.- Parameters:
x- the value- Returns:
- sigmoid(x)
-
sigmoid
public static double sigmoid(double x, double flatteningFactor) Produces a double between 0 and 1 using a flattened sigmoid function.- Parameters:
x- the valueflatteningFactor- the factor- Returns:
- flattened sigmoid
-
sumOfDigits
public static int sumOfDigits(long number) Returns the sum of all individual digits of a number.- Parameters:
number- the number- Returns:
- the sum of digits
-
pascalTriangle
public static double[] pascalTriangle(int n) Returns the n-th row of Pascal's triangle.- Parameters:
n- the row index (number of elements in the row)- Returns:
- the row as an array of doubles.
-