public final class math extends StaticObject
Modifier and Type | Class and Description |
---|---|
static class |
math.random
Some helper method concerning random numbers and random seed generation.
|
static class |
math.statistics
Some helper method concerning statistics.
|
Modifier and Type | Method and Description |
---|---|
static double |
clamp(double v,
double lo,
double hi)
Clamping a value between a pair of boundary values.
|
static void |
divide(double[] values,
double divisor)
Component wise division of the given double array.
|
static double |
max(double[] values)
Deprecated.
Use
math.statistics.max(double[]) instead. |
static double |
min(double[] values)
Deprecated.
Use
math.statistics.min(double[]) instead. |
static long |
minus(long a,
long b)
Subtracts to long values and throws an ArithmeticException in the case of
an overflow.
|
static double[] |
normalize(double[] values)
Normalize the given double array, so that it sum to one.
|
static long |
plus(long a,
long b)
Add to long values and throws an ArithmeticException in the case of an
overflow.
|
static long |
pow(long b,
long e)
Binary exponentiation algorithm.
|
static int[] |
subset(int n,
int k)
Selects a random subset of size
k from a set of size n . |
static void |
subset(int n,
int[] sub)
Selects a random subset of size
sub.length from a set of size
n . |
static int[] |
subset(int n,
int[] sub,
Random random)
Selects a random subset of size
sub.length from a set of size
n . |
static int[] |
subset(int n,
int k,
Random random)
Selects a random subset of size
k from a set of size n . |
static double |
sum(double[] values)
Deprecated.
Use
math.statistics.sum(double[]) instead. |
static long |
sum(long[] values)
Deprecated.
Use
math.statistics.sum(long[]) instead. |
static void |
times(double[] values,
double multiplier)
Component wise multiplication of the given double array.
|
static long |
ulpDistance(double a,
double b)
Return the ULP
distance of the given two double values.
|
static long |
ulpPosition(double a)
Calculating the ULP
position of a double number.
|
public static long plus(long a, long b)
a
- the first summand.b
- the second summand.ArithmeticException
- if the summation would lead to an overflow.public static long minus(long a, long b)
a
- the minuend.b
- the subtrahend.ArithmeticException
- if the subtraction would lead to an overflow.@Deprecated public static double sum(double[] values)
math.statistics.sum(double[])
instead.values
- the values to sum up.values
.NullPointerException
- if the given array is null
.@Deprecated public static long sum(long[] values)
math.statistics.sum(long[])
instead.values
- the values to add.NullPointerException
- if the values are null;public static double[] normalize(double[] values)
values
are
returned.values
- the values to normalize.values
array.NullPointerException
- if the given double array is null
.@Deprecated public static double min(double[] values)
math.statistics.min(double[])
instead.values
- the double array.Double.NaN
if the given array is
empty.NullPointerException
- if the given array is null
.@Deprecated public static double max(double[] values)
math.statistics.max(double[])
instead.values
- the double array.Double.NaN
if the given array is
empty.NullPointerException
- if the given array is null
.public static double clamp(double v, double lo, double hi)
NaN
.v
- the value to clamplo
- the lower bound.hi
- the upper bound.lo if v < lo
hi if hi < v
otherwise, v
public static void times(double[] values, double multiplier)
values
- the double values to multiply.multiplier
- the multiplier.NullPointerException
- if the given double array is null
.public static void divide(double[] values, double divisor)
values
- the double values to divide.divisor
- the divisor.NullPointerException
- if the given double array is null
.public static long pow(long b, long e)
b
- the base number.e
- the exponent.b^e
.public static long ulpDistance(double a, double b)
a
- first double.b
- second double.ArithmeticException
- if the distance doesn't fit in a long value.public static long ulpPosition(double a)
double a = 0.0;
for (int i = 0; i < 10; ++i) {
a = Math.nextAfter(a, Double.POSITIVE_INFINITY);
}
for (int i = 0; i < 19; ++i) {
a = Math.nextAfter(a, Double.NEGATIVE_INFINITY);
System.out.println(
a + "\t" + ulpPosition(a) + "\t" + ulpDistance(0.0, a)
);
}
4.4E-323 9 9 4.0E-323 8 8 3.5E-323 7 7 3.0E-323 6 6 2.5E-323 5 5 2.0E-323 4 4 1.5E-323 3 3 1.0E-323 2 2 4.9E-324 1 1 0.0 0 0 -4.9E-324 -1 1 -1.0E-323 -2 2 -1.5E-323 -3 3 -2.0E-323 -4 4 -2.5E-323 -5 5 -3.0E-323 -6 6 -3.5E-323 -7 7 -4.0E-323 -8 8 -4.4E-323 -9 9
a
- the double number.public static int[] subset(int n, int k)
k
from a set of size n
.n
- the size of the set.k
- the size of the subset.IllegalArgumentException
- if n < k
, k == 0
or if
n*k
will cause an integer overflow.subset(int, int[])
public static int[] subset(int n, int k, Random random)
k
from a set of size n
.n
- the size of the set.k
- the size of the subset.random
- the random number generator used.NullPointerException
- if random
is null
.IllegalArgumentException
- if n < k
, k == 0
or if
n*k
will cause an integer overflow.subset(int, int[], Random)
public static void subset(int n, int[] sub)
Selects a random subset of size sub.length
from a set of size
n
.
Authors: FORTRAN77 original version by Albert Nijenhuis, Herbert Wilf. This version based on the C++ version by John Burkardt.
Reference: Albert Nijenhuis, Herbert Wilf, Combinatorial Algorithms for Computers and Calculators, Second Edition, Academic Press, 1978, ISBN: 0-12-519260-6, LC: QA164.N54.
n
- the size of the set.sub
- the sub set array.NullPointerException
- if sub
is null
.IllegalArgumentException
- if n < sub.length
,
sub.length == 0
or n*sub.length
will cause an
integer overflow.public static int[] subset(int n, int[] sub, Random random)
Selects a random subset of size sub.length
from a set of size
n
.
Authors: FORTRAN77 original version by Albert Nijenhuis, Herbert Wilf. This version based on the C++ version by John Burkardt.
Reference: Albert Nijenhuis, Herbert Wilf, Combinatorial Algorithms for Computers and Calculators, Second Edition, Academic Press, 1978, ISBN: 0-12-519260-6, LC: QA164.N54.
n
- the size of the set.sub
- the sub set array.random
- the random number generator used.NullPointerException
- if sub
or random
is
null
.IllegalArgumentException
- if n < sub.length
,
sub.length == 0
or n*sub.length
will cause an
integer overflow.© 2007-2014 Franz Wilhelmstötter (2014-03-07 19:35)