public class FloatArithmetic extends FloatConstants
Modifier and Type | Method and Description |
---|---|
static float |
binomial(float n,
long k)
Efficiently returns the binomial coefficient, often also referred to as
"n over k" or "n choose k".
|
static float |
binomial(long n,
long k)
Efficiently returns the binomial coefficient, often also referred to as
"n over k" or "n choose k".
|
static long |
ceil(float value)
Returns the smallest
long >= value . |
static float |
chbevl(float x,
float[] coef,
int N)
Evaluates the series of Chebyshev polynomials Ti at argument x/2.
|
static float |
factorial(int k)
Instantly returns the factorial k!.
|
static long |
floor(float value)
Returns the largest
long <= value . |
static float |
log(float base,
float value)
Returns logbasevalue.
|
static float |
log10(float value)
Returns log10value.
|
static float |
log2(float value)
Returns log2value.
|
static float |
logFactorial(int k)
Returns log(k!).
|
static long |
longFactorial(int k)
Instantly returns the factorial k!.
|
static float |
stirlingCorrection(int k)
Returns the StirlingCorrection.
|
public static float binomial(float n, long k)
public static float binomial(long n, long k)
public static long ceil(float value)
long >= value
. 1.0 -> 1, 1.2 -> 2, 1.9 -> 2
. This method is safer than
using (long) Math.ceil(value), because of possible rounding error.public static float chbevl(float x, float[] coef, int N) throws ArithmeticException
N-1 - ' y = > coef[i] T (x/2) - i i=0Coefficients are stored in reverse order, i.e. the zero order term is last in the array. Note N is the number of coefficients, not the order.
If coefficients are for the interval a to b, x must have been transformed to x -> 2(2x - b - a)/(b-a) before entering the routine. This maps x from (a, b) to (-1, 1), over which the Chebyshev polynomials are defined.
If the coefficients are for the inverted interval, in which (a, b) is mapped to (1/b, 1/a), the transformation required is x -> 2(2ab/x - b - a)/(b-a). If b is infinity, this becomes x -> 4a/x - 1.
SPEED:
Taking advantage of the recurrence properties of the Chebyshev polynomials, the routine requires one more addition per loop than evaluating a nested polynomial of the same degree.
x
- argument to the polynomial.coef
- the coefficients of the polynomial.N
- the number of coefficients.ArithmeticException
public static float factorial(int k)
k
- must hold k >= 0.public static long floor(float value)
long <= value
.
1.0 -> 1, 1.2 -> 1, 1.9 -> 1 -
2.0 -> 2, 2.2 -> 2, 2.9 -> 2
public static float log(float base, float value)
public static float log10(float value)
public static float log2(float value)
public static float logFactorial(int k)
k
- must hold k >= 0.public static long longFactorial(int k) throws IllegalArgumentException
k
- must hold k >= 0 && k < 21.IllegalArgumentException
public static float stirlingCorrection(int k)
Correction term of the Stirling approximation for log(k!) (series in 1/k, or table values for small k) with int parameter k.
log k! = (k + 1/2)log(k + 1) - (k + 1) + (1/2)log(2Pi) + stirlingCorrection(k + 1)
log k! = (k + 1/2)log(k) - k + (1/2)log(2Pi) + stirlingCorrection(k)
Jump to the Parallel Colt Homepage