|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.erichseifert.gral.util.MathUtils
public abstract class MathUtils
Abstract class that provides utility functions which are useful for mathematical calculations.
Constructor Summary | |
---|---|
MathUtils()
|
Method Summary | ||
---|---|---|
static boolean |
almostEqual(double a,
double b,
double delta)
Check whether two floating point values match with a given precision. |
|
static int |
binarySearch(double[] a,
double key)
Perform a binary search on a sorted array a to find the
element with the nearest element to key . |
|
static int |
binarySearchCeil(double[] a,
double key)
Perform a binary search on a sorted array a to find the
element with the smallest distance to key . |
|
static int |
binarySearchFloor(double[] a,
double key)
Perform a binary search on a sorted array a to find the
element with the smallest distance to key . |
|
static double |
ceil(double a,
double precision)
Returns a rounded number larger than a with a defined precision. |
|
static double |
floor(double a,
double precision)
Returns a rounded number smaller than a with a defined precision. |
|
static
|
limit(T value,
T min,
T max)
Clamps a value to specified limits: if value is greater than max
then max will be returned. |
|
static
|
randomizedSelect(List<T> a,
int lower,
int upper,
int i)
Perform a randomized search on an unsorted array a to find
the ith smallest element. |
|
static double |
round(double a,
double precision)
Mathematically rounds a number with a defined precision. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MathUtils()
Method Detail |
---|
public static boolean almostEqual(double a, double b, double delta)
a
- First valueb
- Second valuedelta
- Precision
true
if the difference of a and b is
smaller or equal than delta, otherwise false
public static double round(double a, double precision)
a
- Valueprecision
- Precision
public static double floor(double a, double precision)
a
with a defined precision.
a
- Valueprecision
- Precision
public static double ceil(double a, double precision)
a
with a defined precision.
a
- Valueprecision
- Precision
public static int binarySearch(double[] a, double key)
a
to find the
element with the nearest element to key
.
a
- Array with ascending valueskey
- Pivot value
key
public static int binarySearchFloor(double[] a, double key)
a
to find the
element with the smallest distance to key
. The returned
element's value is always less than or equal to key
.
a
- Array with ascending valueskey
- Pivot value
key
public static int binarySearchCeil(double[] a, double key)
a
to find the
element with the smallest distance to key
. The returned
element's value is always greater than or equal to key
.
a
- Array with ascending valueskey
- Pivot value
key
public static <T extends Comparable<T>> T limit(T value, T min, T max)
value
is greater than max
then max
will be returned. If value
is greater than min
then min
will be returned.
T
- Data type of the Value to limit.value
- Value to be clampedmin
- Minimummax
- Maximum
public static <T extends Comparable<T>> int randomizedSelect(List<T> a, int lower, int upper, int i)
Perform a randomized search on an unsorted array a
to find
the ith smallest element. The array contents are be modified during
the operation!
See Cormen et al. (2001): Introduction to Algorithms. 2nd edition. p. 186
T
- Data type of the arraya
- Unsorted arraylower
- Starting indexupper
- End indexi
- Smallness rank of value to search
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |