Class Interpolation
- java.lang.Object
-
- org.apache.commons.statistics.descriptive.Interpolation
-
final class Interpolation extends java.lang.ObjectSupport class for interpolation.- Since:
- 1.1
-
-
Field Summary
Fields Modifier and Type Field Description private static doubleHALF0.5.private static doubleTWO_POW_632^63.private static longUNSIGNED_2_POW_53The value 2^53 converted for comparison as an unsigned integer.
-
Constructor Summary
Constructors Modifier Constructor Description privateInterpolation()No instances.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static doubleinterpolate(double a, double b, double t)Linear interpolation between sorted valuesa <= busing the interpolantttaking care to avoid overflow.(package private) static StatisticResultinterpolate(long a, long b, double t)Linear interpolation between sorted valuesa <= busing the interpolantt.(package private) static doublemean(double x, double y)Compute the arithmetic mean of the two values taking care to avoid overflow.(package private) static doublemean(int x, int y)Compute the arithmetic mean of the two values.(package private) static StatisticResultmean(long x, long y)Compute the arithmetic mean of the two values.(package private) static doublemeanAsDouble(long x, long y)Compute the arithmetic mean of the two values as adouble.(package private) static longmeanAsLong(long x, long y)Compute the arithmetic mean of the two values as along.
-
-
-
Field Detail
-
HALF
private static final double HALF
0.5.- See Also:
- Constant Field Values
-
UNSIGNED_2_POW_53
private static final long UNSIGNED_2_POW_53
The value 2^53 converted for comparison as an unsigned integer.- See Also:
- Constant Field Values
-
TWO_POW_63
private static final double TWO_POW_63
2^63.- See Also:
- Constant Field Values
-
-
Method Detail
-
mean
static double mean(double x, double y)Compute the arithmetic mean of the two values taking care to avoid overflow.- Parameters:
x- Value.y- Value.- Returns:
- the mean
-
mean
static double mean(int x, int y)Compute the arithmetic mean of the two values.- Parameters:
x- Value.y- Value.- Returns:
- the mean
-
meanAsDouble
static double meanAsDouble(long x, long y)Compute the arithmetic mean of the two values as adouble.- Parameters:
x- Value.y- Value.- Returns:
- the mean
-
meanAsLong
static long meanAsLong(long x, long y)Compute the arithmetic mean of the two values as along.The result value is the nearest whole number to the result, with ties rounding towards positive infinity. This is equivalent to the ceiling average.
- Parameters:
x- Value.y- Value.- Returns:
- the mean
-
mean
static StatisticResult mean(long x, long y)
Compute the arithmetic mean of the two values.The result
longvalue is the nearest whole number to the result, with ties rounding towards positive infinity. This is equivalent to the ceiling average.- Parameters:
x- Value.y- Value.- Returns:
- the mean
-
interpolate
static double interpolate(double a, double b, double t)Linear interpolation between sorted valuesa <= busing the interpolantttaking care to avoid overflow.value = a + t * (b - a)
Note
This function has the same properties of as the C++ function std::lerp for
t in (0, 1)andb >= a. It is not a full implementation as it removes explicit checks fort==0andt==1and does not support extrapolation as the usage is intended for interpolation of sorted values. The function is monotonic and avoids overflow for finiteaandb.Interpolation between equal signed infinity arguments will return
a. Alternative implementations may returnNaNfor this case. Thus this method interprets infinity values as equivalent and avoids interpolation.- Parameters:
a- Min value.b- Max value.t- Interpolant in (0, 1).- Returns:
- the value
-
interpolate
static StatisticResult interpolate(long a, long b, double t)
Linear interpolation between sorted valuesa <= busing the interpolantt.value = a + t * (b - a)
The
longvalue is the nearest whole number to the result, with ties rounding towards positive infinity. This value will be in[a, b].The
doublevalue is computed within 1 ULP of the exact result. In some cases this may be outside the range[a, b]due to rounding to a 53-bit representation.Note
This function does not support extrapolation as the usage is intended for interpolation of sorted values.
- Parameters:
a- Min value.b- Max value.t- Interpolant in [0, 1].- Returns:
- the value
-
-