Class MathUtil

Hierarchy: Object , MathUtil
public class MathUtil
Various utility functions for mathematical and numerical operations.
Authors:
mbdavis
public static double clamp(double x, double min, double max)
Clamps a double value to a given range.
Parameters:
x - x the value to clamp
min - min the minimum value of the range
max - max the maximum value of the range
Returns:
the clamped value
public static int clamp(int x, int min, int max)
Clamps an int value to a given range.
Parameters:
x - x the value to clamp
min - min the minimum value of the range
max - max the maximum value of the range
Returns:
the clamped value
public static double log10(double x)
Computes the base-10 logarithm of a double value.
  • If the argument is NaN or less than zero, then the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is positive zero or negative zero, then the result is negative infinity.
Parameters:
x - x a positive number
Returns:
the value log a, the base-10 logarithm of the input value
public static int wrap(int index, int max)
Computes an index which wraps around a given maximum value. For values >= 0, this is equals to val % max. For values < 0, this is equal to max - (-val) % max
Parameters:
index - index the value to wrap
max - max the maximum value (or modulus)
Returns:
the wrapped index
public static double average(double x1, double x2)
Computes the average of two numbers.
Parameters:
x1 - x1 a number
x2 - x2 a number
Returns:
the average of the inputs
public static double max(double v1, double v2, double v3)
public static double max(double v1, double v2, double v3, double v4)
public static double min(double v1, double v2, double v3, double v4)