Class KiwiDoubles

java.lang.Object
org.kiwiproject.base.KiwiDoubles

public final 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 final double
    Default tolerance to use for comparisons when not explicitly specified.
  • Method Summary

    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_FUZZY_EQUALS_TOLERANCE

      public static final double DEFAULT_FUZZY_EQUALS_TOLERANCE
      Default tolerance to use for comparisons when not explicitly specified.
      See Also:
  • Method Details

    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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)