Class MathUtil

java.lang.Object
de.arstwo.twotil.math.MathUtil

public class MathUtil extends Object
Various math-related content that fits nowhere else.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final float
     
    static final double
     
    static final float
     
    static final double
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    aboutEqual(double a, double b, double delta)
    Checks if two doubles are equal within the given tolerance.
    static boolean
    aboutEqual(float a, float b, float delta)
    Checks if two floats are equal within the given tolerance.
    static byte
    abs(byte x)
    Much faster but less generic abs implementation.
    static double
    abs(double x)
    Much faster but less generic abs implementation.
    static float
    abs(float x)
    Much faster but less generic abs implementation.
    static int
    abs(int x)
    Much faster but less generic abs implementation.
    static long
    abs(long x)
    Much faster but less generic abs implementation.
    static short
    abs(short x)
    Much faster but less generic abs implementation.
    static <T extends Comparable<T>>
    T
    withinRange(T value, T min, T max)
    Returns the given value clamped to the min/max valued specified.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • abs

      public static byte abs(byte x)
      Much faster but less generic abs implementation.
    • abs

      public static short abs(short x)
      Much faster but less generic abs implementation.
    • abs

      public static int abs(int x)
      Much faster but less generic abs implementation.
    • abs

      public static long abs(long x)
      Much faster but less generic abs implementation.
    • abs

      public static float abs(float x)
      Much faster but less generic abs implementation.
    • abs

      public static double abs(double x)
      Much faster but less generic abs implementation.
    • aboutEqual

      public static boolean aboutEqual(float a, float b, float delta)
      Checks if two floats are equal within the given tolerance.
      Parameters:
      a - any float
      b - any float
      delta - the maximum difference that is accepted as equal
      Returns:
      true if both values are equal within the given tolerance, false otherwise.
    • aboutEqual

      public static boolean aboutEqual(double a, double b, double delta)
      Checks if two doubles are equal within the given tolerance.
      Parameters:
      a - any double
      b - any double
      delta - the maximum difference that is accepted as equal
      Returns:
      true if both values are equal within the given tolerance, false otherwise.
    • withinRange

      public static <T extends Comparable<T>> T withinRange(T value, T min, T max)
      Returns the given value clamped to the min/max valued specified.
      Type Parameters:
      T - any comparable
      Parameters:
      value - the value to check and return
      min - minimum value to clamp to
      max - maximum value to clamp to
      Returns:
      the value given, clamped to the specified boundaries.