Class KiwiDoubles


  • public class KiwiDoubles
    extends Object
    Double utilities. Mainly wrappers around existing method in Double and DoubleMath that are (in our opinion anyway) easier to work with or read the code, e.g. return a boolean for comparisons instead of an int.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double DEFAULT_FUZZY_EQUALS_TOLERANCE
      Default tolerance to use for comparisons when not explicitly specified.
    • Constructor Summary

      Constructors 
      Constructor Description
      KiwiDoubles()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean areClose​(double value1, double value2)
      Return true if value1 is close to value2, within the default tolerance.
      static boolean areClose​(double value1, double value2, double tolerance)
      Return true if value1 is close to value2, within the given tolerance.
      static boolean areEqual​(double value1, double value2)
      Return true if value1 is numerically equal to value2.
      static boolean areNotEqual​(double value1, double value2)
      Return true if value1 is not numerically equal to value2.
      static boolean isCloseToZero​(double value)
      Return true if value is close to zero, within the default tolerance.
      static boolean isCloseToZero​(double value, double tolerance)
      Return true if value is close to zero, using the given tolerance.
      static boolean isNotZero​(double value)
      Return true if value is not exactly equal to zero.
      static boolean isZero​(double value)
      Return true if value is exactly equal to zero.
    • Field Detail

      • DEFAULT_FUZZY_EQUALS_TOLERANCE

        public static final double DEFAULT_FUZZY_EQUALS_TOLERANCE
        Default tolerance to use for comparisons when not explicitly specified.
        See Also:
        Constant Field Values
    • Constructor Detail

      • KiwiDoubles

        public KiwiDoubles()
    • Method Detail

      • isZero

        public static boolean isZero​(double value)
        Return true if value is exactly equal to zero.
        Parameters:
        value - the value to check
        Returns:
        true if the value is zero
        See Also:
        Double.compare(double, double)
      • isNotZero

        public static boolean isNotZero​(double value)
        Return true if value is not exactly equal to zero.
        Parameters:
        value - the value to check
        Returns:
        true if the value is not zero
        See Also:
        Double.compare(double, double)
      • isCloseToZero

        public static boolean isCloseToZero​(double value)
        Return true if value is close to zero, within the default tolerance.
        Parameters:
        value - the value to check
        Returns:
        true if the value is close to zero using the DEFAULT_FUZZY_EQUALS_TOLERANCE
        See Also:
        DoubleMath.fuzzyEquals(double, double, double), DEFAULT_FUZZY_EQUALS_TOLERANCE
      • isCloseToZero

        public static boolean isCloseToZero​(double value,
                                            double tolerance)
        Return true if value is close to zero, using the given tolerance.
        Parameters:
        value - the value to check
        tolerance - how far away the value can be from zero while still considered equal to zero
        Returns:
        true if the value is close to zero
        See Also:
        DoubleMath.fuzzyEquals(double, double, double)
      • areEqual

        public static boolean areEqual​(double value1,
                                       double value2)
        Return true if value1 is numerically equal to value2.
        Parameters:
        value1 - the first value to compare
        value2 - the second value to compare
        Returns:
        true if value1 equals value2
        See Also:
        Double.compare(double, double)
      • areNotEqual

        public static boolean areNotEqual​(double value1,
                                          double value2)
        Return true if value1 is not numerically equal to value2.
        Parameters:
        value1 - the first value to compare
        value2 - the second value to compare
        Returns:
        true if value1 does not equal value2
        See Also:
        Double.compare(double, double)
      • areClose

        public static boolean areClose​(double value1,
                                       double value2)
        Return true if value1 is close to value2, within the default tolerance.
        Parameters:
        value1 - the first value to compare
        value2 - the second value to compare
        Returns:
        true if value1 is close to value2 using the DEFAULT_FUZZY_EQUALS_TOLERANCE
        See Also:
        DoubleMath.fuzzyEquals(double, double, double), DEFAULT_FUZZY_EQUALS_TOLERANCE
      • areClose

        public static boolean areClose​(double value1,
                                       double value2,
                                       double tolerance)
        Return true if value1 is close to value2, within the given tolerance.
        Parameters:
        value1 - the first value to compare
        value2 - the second value to compare
        tolerance - how far away the values can be from each other while still considered equal
        Returns:
        true if value1 is close to value2 using the DEFAULT_FUZZY_EQUALS_TOLERANCE
        See Also:
        DoubleMath.fuzzyEquals(double, double, double)