Documentation of 'de.erichseifert.gral.util.MathUtils' Java class
MathUtils
de.erichseifert.gral.util

Class MathUtils



  • public abstract class MathUtils
    extends java.lang.Object
    Abstract class that provides utility functions which are useful for mathematical calculations.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static boolean almostEqual(double a, double b, double delta)
      Check whether two floating point values match with a given precision.
      static int binarySearch(double[] a, double key)
      Perform a binary search on a sorted array a to find the element with the nearest element to key.
      static int binarySearchCeil(double[] a, double key)
      Perform a binary search on a sorted array a to find the element with the smallest distance to key.
      static int binarySearchFloor(double[] a, double key)
      Perform a binary search on a sorted array a to find the element with the smallest distance to key.
      static double ceil(double a, double precision)
      Returns a rounded number larger than a with a defined precision.
      static double floor(double a, double precision)
      Returns a rounded number smaller than a with a defined precision.
      static boolean isCalculatable(double n)
      Returns whether a specified double can be used for calculations.
      static boolean isCalculatable(java.lang.Number n)
      Returns whether a specified java.lang.Number object can be used for calculations.
      static double limit(double value, double min, double max)
      Clamps a double number to specified limits: if value is greater than max then max will be returned.
      static float limit(float value, float min, float max)
      Clamps a float number to specified limits: if value is greater than max then max will be returned.
      static int limit(int value, int min, int max)
      Clamps a integer number to specified limits: if value is greater than max then max will be returned.
      static <T extends java.lang.Number>
      T
      limit(T value, T min, T max)
      Clamps a number object to specified limits: if value is greater than max then max will be returned.
      static double magnitude(double base, double n)
      Returns the magnitude of the specified number.
      static double normalizeDegrees(double angle)
      Converts an angle in degrees so that it lies between 0.0 and 360.0.
      static double quantile(java.util.List<java.lang.Double> values, double q)
      Utility method used to calculate arbitrary quantiles from a sorted list of values.
      static <T extends java.lang.Comparable<T>>
      int
      randomizedSelect(java.util.List<T> a, int lower, int upper, int i)
      Perform a randomized search on an unsorted array a to find the ith smallest element.
      static double round(double a, double precision)
      Mathematically rounds a number with a defined precision.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • almostEqual

        public static boolean almostEqual(double a,
                                          double b,
                                          double delta)
        Check whether two floating point values match with a given precision.
        Parameters:
        a - First value
        b - Second value
        delta - Precision
        Returns:
        true if the difference of a and b is smaller or equal than delta, otherwise false
      • round

        public static double round(double a,
                                   double precision)
        Mathematically rounds a number with a defined precision.
        Parameters:
        a - Value
        precision - Precision
        Returns:
        Rounded value
      • floor

        public static double floor(double a,
                                   double precision)
        Returns a rounded number smaller than a with a defined precision.
        Parameters:
        a - Value
        precision - Precision
        Returns:
        Rounded value
      • ceil

        public static double ceil(double a,
                                  double precision)
        Returns a rounded number larger than a with a defined precision.
        Parameters:
        a - Value
        precision - Precision
        Returns:
        Rounded value
      • binarySearch

        public static int binarySearch(double[] a,
                                       double key)
        Perform a binary search on a sorted array a to find the element with the nearest element to key.
        Parameters:
        a - Array with ascending values
        key - Pivot value
        Returns:
        Index of the array element whose value is nearly or exactly key
      • binarySearchFloor

        public static int binarySearchFloor(double[] a,
                                            double key)
        Perform a binary search on a sorted array a to find the element with the smallest distance to key. The returned element's value is always less than or equal to key.
        Parameters:
        a - Array with ascending values
        key - Pivot value
        Returns:
        Index of the array element whose value is less than or equal to key
      • binarySearchCeil

        public static int binarySearchCeil(double[] a,
                                           double key)
        Perform a binary search on a sorted array a to find the element with the smallest distance to key. The returned element's value is always greater than or equal to key.
        Parameters:
        a - Array with ascending values
        key - Pivot value
        Returns:
        Index of the array element whose value is greater than or equal to key
      • limit

        public static <T extends java.lang.Number> T limit(T value,
                                                           T min,
                                                           T max)
        Clamps a number object to specified limits: if value is greater than max then max will be returned. If value is greater than min then min will be returned.
        Type Parameters:
        T - Numeric data type
        Parameters:
        value - Double value to be clamped
        min - Minimum
        max - Maximum
        Returns:
        Clamped value
      • limit

        public static double limit(double value,
                                   double min,
                                   double max)
        Clamps a double number to specified limits: if value is greater than max then max will be returned. If value is greater than min then min will be returned.
        Parameters:
        value - Double value to be clamped
        min - Minimum
        max - Maximum
        Returns:
        Clamped value
      • limit

        public static float limit(float value,
                                  float min,
                                  float max)
        Clamps a float number to specified limits: if value is greater than max then max will be returned. If value is greater than min then min will be returned.
        Parameters:
        value - Float value to be clamped
        min - Minimum
        max - Maximum
        Returns:
        Clamped value
      • limit

        public static int limit(int value,
                                int min,
                                int max)
        Clamps a integer number to specified limits: if value is greater than max then max will be returned. If value is greater than min then min will be returned.
        Parameters:
        value - Integer value to be clamped
        min - Minimum
        max - Maximum
        Returns:
        Clamped value
      • randomizedSelect

        public static <T extends java.lang.Comparable<T>> int randomizedSelect(java.util.List<T> a,
                                                                               int lower,
                                                                               int upper,
                                                                               int i)

        Perform a randomized search on an unsorted array a to find the ith smallest element. The array contents are be modified during the operation!

        See Cormen et al. (2001): Introduction to Algorithms. 2nd edition. p. 186

        Type Parameters:
        T - Data type of the array
        Parameters:
        a - Unsorted array
        lower - Starting index
        upper - End index
        i - Smallness rank of value to search starting at 1
        Returns:
        Index of the element that is the ith smallest in array a
      • magnitude

        public static double magnitude(double base,
                                       double n)

        Returns the magnitude of the specified number. Example for magnitude base 10:

        -0.05 -0.01
        0.05 0.01
        3.14 1.00
        54.32 10.00
        123.45100.00
        Parameters:
        base - Base.
        n - Number.
        Returns:
        Magnitude.
      • isCalculatable

        public static boolean isCalculatable(java.lang.Number n)
        Returns whether a specified java.lang.Number object can be used for calculations. null values, NaN values or infinite values are considered as non-calculatable.
        Parameters:
        n - Number object.
        Returns:
        whether n can be used for calculations.
      • isCalculatable

        public static boolean isCalculatable(double n)
        Returns whether a specified double can be used for calculations. NaN values or infinite values are considered non-calculatable.
        Parameters:
        n - double value
        Returns:
        whether n can be used for calculations.
      • normalizeDegrees

        public static double normalizeDegrees(double angle)
        Converts an angle in degrees so that it lies between 0.0 and 360.0.
        Parameters:
        angle - Arbitrary angle in degrees.
        Returns:
        Angle between 0.0 and 360.0.

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.