Class XMathUtils
java.lang.Object
de.xima.fc.utils.XMathUtils
Utility class for mathematical operations.
- Since:
- 8.4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleThe mathematical constant sqrt(2), which is approximately 1.414. -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleinterpolateLinearly(double start, double end, double ratio) Interpolates between two values using linear interpolation.static booleanisFinite(double value) Checks if a double value is finite (not NaN or infinite).static booleanisFinite(float value) Checks if a float value is finite (not NaN or infinite).static booleanisFinite(int value) static booleanisFinite(long value) static booleanChecks if a double value is finite (not null, NaN or infinite).static booleanChecks if a float value is finite (not null, NaN or infinite).static booleanstatic booleanstatic doublemax(double a, double b) Similar toMath.max, but handles NaN values by returning the other value if one is NaN.static doublemax(double a, double b, double c) Returns the largest of three double values, functionally equivalent to: max(max(a, b), c).static doublemax(double a, double b, double c, double d) Returns the largest of four double values, functionally equivalent to: max(max(a, b), max(c, d)).static doublemin(double a, double b) Similar toMath.min, but handles NaN values by returning the other value if one is NaN.static doublemin(double a, double b, double c) Returns the smallest of three double values, functionally equivalent to: min(min(a, b), c).static doublemin(double a, double b, double c, double d) Returns the smallest of four double values, functionally equivalent to: min(min(a, b), min(c, d)).
-
Field Details
-
SQRT_2
public static final double SQRT_2The mathematical constant sqrt(2), which is approximately 1.414.
-
-
Method Details
-
interpolateLinearly
public static double interpolateLinearly(double start, double end, double ratio) Interpolates between two values using linear interpolation.interpolateLinearly(2, 6, -0.25) = 1 interpolateLinearly(2, 6, 0.00) = 2 interpolateLinearly(2, 6, 0.25) = 3 interpolateLinearly(2, 6, 0.50) = 4 interpolateLinearly(2, 6, 0.75) = 5 interpolateLinearly(2, 6, 1.00) = 6 interpolateLinearly(2, 6, 1.25) = 7
- Parameters:
start- The start value.end- The end value.ratio- The ratio between the start and end values. Should be in the range [0, 1]. Values outside this range returns values outside the [start, end] range.- Returns:
- The interpolated value.
-
isFinite
-
isFinite
-
isFinite
-
isFinite
-
isFinite
public static boolean isFinite(float value) Checks if a float value is finite (not NaN or infinite).- Parameters:
value- The float value to check.- Returns:
- True if the value is finite, false otherwise.
-
isFinite
Checks if a float value is finite (not null, NaN or infinite).- Parameters:
value- The float value to check.- Returns:
- True if the value is finite, false otherwise.
-
isFinite
public static boolean isFinite(double value) Checks if a double value is finite (not NaN or infinite).- Parameters:
value- The double value to check.- Returns:
- True if the value is finite, false otherwise.
-
isFinite
Checks if a double value is finite (not null, NaN or infinite).- Parameters:
value- The double value to check.- Returns:
- True if the value is finite, false otherwise.
-
max
public static double max(double a, double b) Similar toMath.max, but handles NaN values by returning the other value if one is NaN.- Parameters:
a- The first value to compare.b- The second value to compare.- Returns:
- The larger of the two values.
-
max
public static double max(double a, double b, double c) Returns the largest of three double values, functionally equivalent to: max(max(a, b), c).- Parameters:
a- The first value to compare.b- The second value to compare.c- The third value to compare.- Returns:
- The largest of the three values.
-
max
public static double max(double a, double b, double c, double d) Returns the largest of four double values, functionally equivalent to: max(max(a, b), max(c, d)).- Parameters:
a- The first value to compare.b- The second value to compare.c- The third value to compare.d- The fourth value to compare.- Returns:
- The largest of the three values.
-
min
public static double min(double a, double b) Similar toMath.min, but handles NaN values by returning the other value if one is NaN.- Parameters:
a- The first value to compare.b- The second value to compare.- Returns:
- The smaller of the two values.
-
min
public static double min(double a, double b, double c) Returns the smallest of three double values, functionally equivalent to: min(min(a, b), c).- Parameters:
a- The first value to compare.b- The second value to compare.c- The third value to compare.- Returns:
- The smallest of the three values.
-
min
public static double min(double a, double b, double c, double d) Returns the smallest of four double values, functionally equivalent to: min(min(a, b), min(c, d)).- Parameters:
a- The first value to compare.b- The second value to compare.c- The third value to compare.d- The fourth value to compare.- Returns:
- The smallest of the three values.
-