java.lang.Object
com.intellij.util.MathUtil
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static booleanbetween(double min, double med, double max, double epsilon) static booleanbetween(float min, float med, float max, float epsilon) static doubleclamp(double value, double min, double max) Clamps the value to fit between min and maxstatic floatclamp(float value, float min, float max) Clamps the value to fit between min and maxstatic intclamp(int value, int min, int max) Clamps the value to fit between min and maxstatic longclamp(long value, long min, long max) Clamps the value to fit between min and maxstatic intcompare(double a, double b, double epsilon) Imprecise version ofDouble.compare(double, double)with the given accuracy.static intcompare(float a, float b, float epsilon) Imprecise version ofFloat.compare(float, float)with the given accuracy.static booleanequals(double a, double b, double epsilon) static booleanequals(float a, float b, float epsilon) static intnonNegativeAbs(int a) Returns the closest non-negativeintvalue to the absolute value ofa.
-
构造器详细资料
-
MathUtil
public MathUtil()
-
-
方法详细资料
-
nonNegativeAbs
public static int nonNegativeAbs(int a) Returns the closest non-negativeintvalue to the absolute value ofa. Works the same way asMath.abs(int)for all values exceptInteger.MIN_VALUE, for whichMath.abs(int)returns negative value but this method returnsInteger.MAX_VALUE. Use this method instead ofthe standard oneif it's important to get non-negative result andInteger.MIN_VALUEmay be passed as an argument (e.g. if the argument is a result ofObject.hashCode()orRandom.nextInt()call). -
clamp
public static int clamp(int value, int min, int max) Clamps the value to fit between min and max- 参数:
value- value to clampmin- min allowed valuemax- max allowed value- 返回:
- a clamped value that fits into [min..max] interval
- 抛出:
IllegalArgumentException- if min > max
-
clamp
public static long clamp(long value, long min, long max) Clamps the value to fit between min and max- 参数:
value- value to clampmin- min allowed valuemax- max allowed value- 返回:
- a clamped value that fits into [min..max] interval
- 抛出:
IllegalArgumentException- if min > max
-
clamp
public static double clamp(double value, double min, double max) Clamps the value to fit between min and max- 参数:
value- value to clampmin- min allowed valuemax- max allowed value- 返回:
- a clamped value that fits into [min..max] interval
- 抛出:
IllegalArgumentException- if min > max
-
clamp
public static float clamp(float value, float min, float max) Clamps the value to fit between min and max- 参数:
value- value to clampmin- min allowed valuemax- max allowed value- 返回:
- a clamped value that fits into [min..max] interval
- 抛出:
IllegalArgumentException- if min > max
-
equals
public static boolean equals(float a, float b, float epsilon) - 返回:
trueifa == baccurate toepsilon
-
equals
public static boolean equals(double a, double b, double epsilon) - 返回:
trueifa == baccurate toepsilon
-
compare
public static int compare(float a, float b, float epsilon) Imprecise version ofFloat.compare(float, float)with the given accuracy.- 参数:
epsilon- Accuracy
-
compare
public static int compare(double a, double b, double epsilon) Imprecise version ofDouble.compare(double, double)with the given accuracy.- 参数:
epsilon- Accuracy
-
between
public static boolean between(float min, float med, float max, float epsilon) - 返回:
trueifmin <= med <= maxaccurate toepsilon
-
between
public static boolean between(double min, double med, double max, double epsilon) - 返回:
trueifmin <= med <= maxaccurate toepsilon
-