Interface Precision.DoubleEquivalence

  • Enclosing class:
    Precision

    public static interface Precision.DoubleEquivalence
    Interface containing comparison operations for doubles that allow values to be considered equal even if they are not exactly equal. It is intended for comparing outputs of a computation where floating point errors may have occurred.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      int compare​(double a, double b)
      Compares two values.
      default boolean eq​(double a, double b)
      Indicates whether given values are considered equal to each other.
      default boolean eqZero​(double a)
      Indicates whether the given value is considered equal to zero.
      default boolean gt​(double a, double b)
      Indicates whether the first argument is strictly greater than the second.
      default boolean gte​(double a, double b)
      Indicates whether the first argument is greater than or considered equal to the second.
      default boolean lt​(double a, double b)
      Indicates whether the first argument is strictly smaller than the second.
      default boolean lte​(double a, double b)
      Indicates whether the first argument is smaller or considered equal to the second.
      default double signum​(double a)
      Returns the sign of the argument.
    • Method Detail

      • eq

        default boolean eq​(double a,
                           double b)
        Indicates whether given values are considered equal to each other.
        Parameters:
        a - Value.
        b - Value.
        Returns:
        true if the given values are considered equal.
      • eqZero

        default boolean eqZero​(double a)
        Indicates whether the given value is considered equal to zero. It is a shortcut for eq(a, 0.0).
        Parameters:
        a - Value.
        Returns:
        true if the argument is considered equal to zero.
      • lt

        default boolean lt​(double a,
                           double b)
        Indicates whether the first argument is strictly smaller than the second.
        Parameters:
        a - Value.
        b - Value.
        Returns:
        true if a < b
      • lte

        default boolean lte​(double a,
                            double b)
        Indicates whether the first argument is smaller or considered equal to the second.
        Parameters:
        a - Value.
        b - Value.
        Returns:
        true if a <= b
      • gt

        default boolean gt​(double a,
                           double b)
        Indicates whether the first argument is strictly greater than the second.
        Parameters:
        a - Value.
        b - Value.
        Returns:
        true if a > b
      • gte

        default boolean gte​(double a,
                            double b)
        Indicates whether the first argument is greater than or considered equal to the second.
        Parameters:
        a - Value.
        b - Value.
        Returns:
        true if a >= b
      • signum

        default double signum​(double a)
        Returns the sign of the argument. The returned value is
        • -0.0 if a is considered equal to zero and negatively signed,
        • +0.0 if a is considered equal to zero and positively signed,
        • -1.0 if a is considered less than zero,
        • +1.0 if a is considered greater than zero.

        The equality with zero uses the eqZero method.

        Parameters:
        a - Value.
        Returns:
        the sign (or a if a == 0 or a is NaN).
        See Also:
        eqZero(double)
      • compare

        int compare​(double a,
                    double b)
        Compares two values. The returned value is
        • 0 if the arguments are considered equal,
        • -1 if a < b,
        • +1 if a > b or if either value is NaN.
        Parameters:
        a - Value.
        b - Value.
        Returns:
        0 if the values are considered equal, -1 if the first is smaller than the second, 1 is the first is larger than the second or either value is NaN.