mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[util] Added some common operations with floating points into MathUtil
GitOrigin-RevId: e7e02e7360d64a8310611c07160f8325f572e35f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9722cf53a8
commit
48fde63fa0
@@ -73,4 +73,48 @@ public final class MathUtil {
|
||||
}
|
||||
return Math.min(max, Math.max(value, min));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if {@code a == b} accurate to {@code epsilon}
|
||||
*/
|
||||
public static boolean equals(float a, float b, float epsilon) {
|
||||
return Math.abs(a - b) < epsilon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if {@code a == b} accurate to {@code epsilon}
|
||||
*/
|
||||
public static boolean equals(double a, double b, double epsilon) {
|
||||
return Math.abs(a - b) < epsilon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Imprecise version of {@link Float#compare(float, float)} with the given accuracy.
|
||||
* @param epsilon Accuracy
|
||||
*/
|
||||
public static int compare(float a, float b, float epsilon) {
|
||||
return Math.abs(a - b) < epsilon ? 0 : Float.compare(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Imprecise version of {@link Double#compare(double, double)} with the given accuracy.
|
||||
* @param epsilon Accuracy
|
||||
*/
|
||||
public static int compare(double a, double b, double epsilon) {
|
||||
return Math.abs(a - b) < epsilon ? 0 : Double.compare(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if {@code min <= med <= max} accurate to {@code epsilon}
|
||||
*/
|
||||
public static boolean between(float min, float med, float max, float epsilon) {
|
||||
return compare(min, med, epsilon) < 0 && compare(med, max, epsilon) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if {@code min <= med <= max} accurate to {@code epsilon}
|
||||
*/
|
||||
public static boolean between(double min, double med, double max, double epsilon) {
|
||||
return compare(min, med, epsilon) < 0 && compare(med, max, epsilon) < 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user