Class NumberUtil

java.lang.Object
de.tomatengames.util.NumberUtil

public class NumberUtil extends Object
Provides utilities to handle numbers.
Since:
1.3
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    limit(double value, double min, double max)
    Limits the specified value to the range [min, max].
    static int
    limit(int value, int min, int max)
    Limits the specified value to the range [min, max].
    static long
    limit(long value, long min, long max)
    Limits the specified value to the range [min, max].

    Methods inherited from class Object

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

    • limit

      public static int limit(int value, int min, int max)
      Limits the specified value to the range [min, max].

      If min <= value <= max, value is returned. If value < min, min is returned. If value > max, max is returned. If min > max, the returned value is undefined.

      Parameters:
      value - The value.
      min - The minimum of the range. Must be less than or equal max.
      max - The maximum of the range. Must be greater than or equal min.
      Returns:
      The value in the range [min, max].
    • limit

      public static long limit(long value, long min, long max)
      Limits the specified value to the range [min, max].

      If min <= value <= max, value is returned. If value < min, min is returned. If value > max, max is returned. If min > max, the returned value is undefined.

      Parameters:
      value - The value.
      min - The minimum of the range. Must be less than or equal max.
      max - The maximum of the range. Must be greater than or equal min.
      Returns:
      The value in the range [min, max].
    • limit

      public static double limit(double value, double min, double max)
      Limits the specified value to the range [min, max].

      If min <= value <= max, value is returned. If value < min, min is returned. If value > max, max is returned. If min > max, the returned value is undefined.

      Parameters:
      value - The value.
      min - The minimum of the range. Must be less than or equal max.
      max - The maximum of the range. Must be greater than or equal min.
      Returns:
      The value in the range [min, max].