Class XMathUtils


  • public final class XMathUtils
    extends Object
    Utility class for mathematical operations.
    Since:
    8.4.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double SQRT_2
      The mathematical constant sqrt(2), which is approximately 1.414.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double interpolateLinearly​(double start, double end, double ratio)
      Interpolates between two values using linear interpolation.
      static boolean isFinite​(double value)
      Checks if a double value is finite (not NaN or infinite).
      static boolean isFinite​(float value)
      Checks if a float value is finite (not NaN or infinite).
      static boolean isFinite​(int value)
      Checks if an integer value is finite (between MIN_VALUE and MAX_VALUE).
      static boolean isFinite​(long value)
      Checks if a long value is finite (between MIN_VALUE and MAX_VALUE).
      static boolean isFinite​(Double value)
      Checks if a double value is finite (not null, NaN or infinite).
      static boolean isFinite​(Float value)
      Checks if a float value is finite (not null, NaN or infinite).
      static boolean isFinite​(Integer value)
      Checks if an integer value is finite (not null and between MIN_VALUE and MAX_VALUE).
      static boolean isFinite​(Long value)
      Checks if a long value is finite (not null and between MIN_VALUE and MAX_VALUE).
      static double max​(double a, double b)
      Similar to Math.max, but handles NaN values by returning the other value if one is NaN.
      static double max​(double a, double b, double c)
      Returns the largest of three double values, functionally equivalent to: max(max(a, b), c).
      static double max​(double a, double b, double c, double d)
      Returns the largest of four double values, functionally equivalent to: max(max(a, b), max(c, d)).
      static double min​(double a, double b)
      Similar to Math.min, but handles NaN values by returning the other value if one is NaN.
      static double min​(double a, double b, double c)
      Returns the smallest of three double values, functionally equivalent to: min(min(a, b), c).
      static double min​(double a, double b, double c, double d)
      Returns the smallest of four double values, functionally equivalent to: min(min(a, b), min(c, d)).
    • Field Detail

      • SQRT_2

        public static final double SQRT_2
        The mathematical constant sqrt(2), which is approximately 1.414.
    • Method Detail

      • interpolateLinearly

        public static double interpolateLinearly​(double start,
                                                 double end,
                                                 double ratio)
        Interpolates between two values using linear interpolation.
            interpolateLinearly(2, 6, -0.25) = 1
            interpolateLinearly(2, 6,  0.00) = 2
            interpolateLinearly(2, 6,  0.25) = 3
            interpolateLinearly(2, 6,  0.50) = 4
            interpolateLinearly(2, 6,  0.75) = 5
            interpolateLinearly(2, 6,  1.00) = 6
            interpolateLinearly(2, 6,  1.25) = 7
         
        Parameters:
        start - The start value.
        end - The end value.
        ratio - The ratio between the start and end values. Should be in the range [0, 1]. Values outside this range returns values outside the [start, end] range.
        Returns:
        The interpolated value.
      • isFinite

        public static boolean isFinite​(int value)
        Checks if an integer value is finite (between MIN_VALUE and MAX_VALUE).
        Parameters:
        value - The long value to check.
        Returns:
        True if the value is finite, false otherwise.
      • isFinite

        public static boolean isFinite​(Integer value)
        Checks if an integer value is finite (not null and between MIN_VALUE and MAX_VALUE).
        Parameters:
        value - The long value to check.
        Returns:
        True if the value is finite, false otherwise.
      • isFinite

        public static boolean isFinite​(long value)
        Checks if a long value is finite (between MIN_VALUE and MAX_VALUE).
        Parameters:
        value - The long value to check.
        Returns:
        True if the value is finite, false otherwise.
      • isFinite

        public static boolean isFinite​(Long value)
        Checks if a long value is finite (not null and between MIN_VALUE and MAX_VALUE).
        Parameters:
        value - The long value to check.
        Returns:
        True if the value is finite, false otherwise.
      • isFinite

        public static boolean isFinite​(float value)
        Checks if a float value is finite (not NaN or infinite).
        Parameters:
        value - The float value to check.
        Returns:
        True if the value is finite, false otherwise.
      • isFinite

        public static boolean isFinite​(Float value)
        Checks if a float value is finite (not null, NaN or infinite).
        Parameters:
        value - The float value to check.
        Returns:
        True if the value is finite, false otherwise.
      • isFinite

        public static boolean isFinite​(double value)
        Checks if a double value is finite (not NaN or infinite).
        Parameters:
        value - The double value to check.
        Returns:
        True if the value is finite, false otherwise.
      • isFinite

        public static boolean isFinite​(Double value)
        Checks if a double value is finite (not null, NaN or infinite).
        Parameters:
        value - The double value to check.
        Returns:
        True if the value is finite, false otherwise.
      • max

        public static double max​(double a,
                                 double b)
        Similar to Math.max, but handles NaN values by returning the other value if one is NaN.
        Parameters:
        a - The first value to compare.
        b - The second value to compare.
        Returns:
        The larger of the two values.
      • max

        public static double max​(double a,
                                 double b,
                                 double c)
        Returns the largest of three double values, functionally equivalent to: max(max(a, b), c).
        Parameters:
        a - The first value to compare.
        b - The second value to compare.
        c - The third value to compare.
        Returns:
        The largest of the three values.
      • max

        public static double max​(double a,
                                 double b,
                                 double c,
                                 double d)
        Returns the largest of four double values, functionally equivalent to: max(max(a, b), max(c, d)).
        Parameters:
        a - The first value to compare.
        b - The second value to compare.
        c - The third value to compare.
        d - The fourth value to compare.
        Returns:
        The largest of the three values.
      • min

        public static double min​(double a,
                                 double b)
        Similar to Math.min, but handles NaN values by returning the other value if one is NaN.
        Parameters:
        a - The first value to compare.
        b - The second value to compare.
        Returns:
        The smaller of the two values.
      • min

        public static double min​(double a,
                                 double b,
                                 double c)
        Returns the smallest of three double values, functionally equivalent to: min(min(a, b), c).
        Parameters:
        a - The first value to compare.
        b - The second value to compare.
        c - The third value to compare.
        Returns:
        The smallest of the three values.
      • min

        public static double min​(double a,
                                 double b,
                                 double c,
                                 double d)
        Returns the smallest of four double values, functionally equivalent to: min(min(a, b), min(c, d)).
        Parameters:
        a - The first value to compare.
        b - The second value to compare.
        c - The third value to compare.
        d - The fourth value to compare.
        Returns:
        The smallest of the three values.