Class MathUtilities

java.lang.Object
de.gurkenlabs.litiengine.util.MathUtilities

public class MathUtilities extends Object
Utility class for mathematical operations.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    equals(double d1, double d2, double epsilon)
    Checks if two double values are equal within a given epsilon.
    static double
    getAverage(double[] numbers)
    Calculates the average of an array of double values.
    static float
    getAverage(float[] numbers)
    Calculates the average of an array of float values.
    static double
    getAverage(int[] numbers)
    Calculates the average of an array of int values.
    static int
    getFullPercent(double value, double fraction)
    Calculates the percentage of a fraction relative to a value.
    static int
    getMax(int... numbers)
    Finds the maximum value in an array of int values.
    static double
    getPercent(double value, double fraction)
    Calculates the percentage of a fraction relative to a value.
    static boolean
    isInt(double value)
    Checks if a double value is an integer.
    static boolean
    isOddNumber(int num)
    Checks if an int value is an odd number.
    static double
    round(double value, int places)
    Rounds a double value to the specified number of decimal places.
    static float
    round(float value, int places)
    Rounds a float value to the specified number of decimal places.

    Methods inherited from class java.lang.Object

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

    • equals

      public static boolean equals(double d1, double d2, double epsilon)
      Checks if two double values are equal within a given epsilon.
      Parameters:
      d1 - the first double value
      d2 - the second double value
      epsilon - the tolerance within which the two values are considered equal
      Returns:
      true if the absolute difference between d1 and d2 is less than or equal to epsilon, false otherwise
    • round

      public static float round(float value, int places)
      Rounds a float value to the specified number of decimal places.
      Parameters:
      value - the float value to be rounded
      places - the number of decimal places to round to
      Returns:
      the rounded float value
    • round

      public static double round(double value, int places)
      Rounds a double value to the specified number of decimal places.
      Parameters:
      value - the double value to be rounded
      places - the number of decimal places to round to
      Returns:
      the rounded double value
      Throws:
      IllegalArgumentException - if the number of decimal places is negative
    • getAverage

      public static double getAverage(double[] numbers)
      Calculates the average of an array of double values.
      Parameters:
      numbers - the array of double values
      Returns:
      the average of the values in the array
    • getAverage

      public static float getAverage(float[] numbers)
      Calculates the average of an array of float values.
      Parameters:
      numbers - the array of float values
      Returns:
      the average of the values in the array
    • getAverage

      public static double getAverage(int[] numbers)
      Calculates the average of an array of int values.
      Parameters:
      numbers - the array of int values
      Returns:
      the average of the values in the array
    • getMax

      public static int getMax(int... numbers)
      Finds the maximum value in an array of int values.
      Parameters:
      numbers - the array of int values
      Returns:
      the maximum value in the array
    • isInt

      public static boolean isInt(double value)
      Checks if a double value is an integer.
      Parameters:
      value - the double value to check
      Returns:
      true if the value is an integer, false otherwise
    • isOddNumber

      public static boolean isOddNumber(int num)
      Checks if an int value is an odd number.
      Parameters:
      num - the int value to check
      Returns:
      true if the value is odd, false otherwise
    • getFullPercent

      public static int getFullPercent(double value, double fraction)
      Calculates the percentage of a fraction relative to a value.
      Parameters:
      value - the total value
      fraction - the fraction of the total value
      Returns:
      the percentage of the fraction relative to the total value
    • getPercent

      public static double getPercent(double value, double fraction)
      Calculates the percentage of a fraction relative to a value.
      Parameters:
      value - the total value
      fraction - the fraction of the total value
      Returns:
      the percentage of the fraction relative to the total value