Package pi.util

Class MathUtil

java.lang.Object
pi.util.MathUtil

public class MathUtil extends Object
Author:
Steffen Wilke, Matthias Wilke
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte
    clamp(byte value, byte min, byte max)
    Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
    static double
    clamp(double value, double min, double max)
    Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
    static float
    clamp(float value, float min, float max)
    Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
    static int
    clamp(int value, int min, int max)
    Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
    static long
    clamp(long value, long min, long max)
    Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
    static short
    clamp(short value, short min, short max)
    Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
    static boolean
    equals(double d1, double d2, double epsilon)
     
    static double
    getAverage(double[] numbers)
     
    static float
    getAverage(float[] numbers)
     
    static int
    getAverage(int[] numbers)
     
    static int
    getFullPercent(double value, double fraction)
     
    static int
    getMax(int... numbers)
     
    static double
    getPercent(double value, double fraction)
     
    static boolean
    isInt(double value)
     
    static boolean
    isOddNumber(int num)
     
    static double
    round(double value, int places)
     
    static float
    round(float value, int 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)
    • round

      public static float round(float value, int places)
    • round

      public static double round(double value, int places)
    • clamp

      public static double clamp(double value, double min, double max)
      Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
      Parameters:
      value - The value to be clamped.
      min - The minimum value to be accepted.
      max - The maximum value to be accepted.
      Returns:
      A value clamped to the specified boundaries.
    • clamp

      public static float clamp(float value, float min, float max)
      Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
      Parameters:
      value - The value to be clamped.
      min - The minimum value to be accepted.
      max - The maximum value to be accepted.
      Returns:
      A value clamped to the specified boundaries.
    • clamp

      public static byte clamp(byte value, byte min, byte max)
      Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
      Parameters:
      value - The value to be clamped.
      min - The minimum value to be accepted.
      max - The maximum value to be accepted.
      Returns:
      A value clamped to the specified boundaries.
    • clamp

      public static short clamp(short value, short min, short max)
      Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
      Parameters:
      value - The value to be clamped.
      min - The minimum value to be accepted.
      max - The maximum value to be accepted.
      Returns:
      A value clamped to the specified boundaries.
    • clamp

      public static int clamp(int value, int min, int max)
      Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
      Parameters:
      value - The value to be clamped.
      min - The minimum value to be accepted.
      max - The maximum value to be accepted.
      Returns:
      A value clamped to the specified boundaries.
    • clamp

      public static long clamp(long value, long min, long max)
      Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
      Parameters:
      value - The value to be clamped.
      min - The minimum value to be accepted.
      max - The maximum value to be accepted.
      Returns:
      A value clamped to the specified boundaries.
    • getAverage

      public static double getAverage(double[] numbers)
    • getAverage

      public static float getAverage(float[] numbers)
    • getAverage

      public static int getAverage(int[] numbers)
    • getMax

      public static int getMax(int... numbers)
    • isInt

      public static boolean isInt(double value)
    • isOddNumber

      public static boolean isOddNumber(int num)
    • getFullPercent

      public static int getFullPercent(double value, double fraction)
    • getPercent

      public static double getPercent(double value, double fraction)