类 MathUtil

java.lang.Object
com.intellij.util.MathUtil

public final class MathUtil extends Object
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static boolean
    between(double min, double med, double max, double epsilon)
     
    static boolean
    between(float min, float med, float max, float epsilon)
     
    static double
    clamp(double value, double min, double max)
    Clamps the value to fit between min and max
    static float
    clamp(float value, float min, float max)
    Clamps the value to fit between min and max
    static int
    clamp(int value, int min, int max)
    Clamps the value to fit between min and max
    static long
    clamp(long value, long min, long max)
    Clamps the value to fit between min and max
    static int
    compare(double a, double b, double epsilon)
    Imprecise version of Double.compare(double, double) with the given accuracy.
    static int
    compare(float a, float b, float epsilon)
    Imprecise version of Float.compare(float, float) with the given accuracy.
    static boolean
    equals(double a, double b, double epsilon)
     
    static boolean
    equals(float a, float b, float epsilon)
     
    static int
    Returns the closest non-negative int value to the absolute value of a.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • MathUtil

      public MathUtil()
  • 方法详细资料

    • nonNegativeAbs

      public static int nonNegativeAbs(int a)
      Returns the closest non-negative int value to the absolute value of a. Works the same way as Math.abs(int) for all values except Integer.MIN_VALUE, for which Math.abs(int) returns negative value but this method returns Integer.MAX_VALUE.

      Use this method instead of the standard one if it's important to get non-negative result and Integer.MIN_VALUE may be passed as an argument (e.g. if the argument is a result of Object.hashCode() or Random.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 clamp
      min - min allowed value
      max - 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 clamp
      min - min allowed value
      max - 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 clamp
      min - min allowed value
      max - 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 clamp
      min - min allowed value
      max - 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)
      返回:
      true if a == b accurate to epsilon
    • equals

      public static boolean equals(double a, double b, double epsilon)
      返回:
      true if a == b accurate to epsilon
    • compare

      public static int compare(float a, float b, float epsilon)
      Imprecise version of Float.compare(float, float) with the given accuracy.
      参数:
      epsilon - Accuracy
    • compare

      public static int compare(double a, double b, double epsilon)
      Imprecise version of Double.compare(double, double) with the given accuracy.
      参数:
      epsilon - Accuracy
    • between

      public static boolean between(float min, float med, float max, float epsilon)
      返回:
      true if min <= med <= max accurate to epsilon
    • between

      public static boolean between(double min, double med, double max, double epsilon)
      返回:
      true if min <= med <= max accurate to epsilon