Class UlpDistanceBound

  • All Implemented Interfaces:
    FloatingPointTolerance

    public class UlpDistanceBound
    extends Object
    implements FloatingPointTolerance
    Checks equivalence based on the distance between two floating point numbers in units of least precision (ULP). Two values are considered equal if this error is less than a fixed bound.

    The ULP is based on the representation of the values rather than the values itself. As errors in single- and double-precision floating point arithmetic stem from the inability to precisely represent values, measuring the distance in ULPs can provide a bound which is more consistent in behavior, regardless of the the scale of the the values.

    As the ULP is based on the IEEE 754 specification for floating point, this tolerance is not supported for BigDecimal.

    • Constructor Detail

      • UlpDistanceBound

        public UlpDistanceBound​(int maxUlps)
        Define a fixed bound on the distance between two floating point values, measured in ULPs.
        Parameters:
        maxUlps - the fixed bound on the distance, in ULPS
        Throws:
        com.pervasive.datarush.graphs.physical.InvalidPropertyValueException - if epsilon is negative.
    • Method Detail

      • isWithinTolerance

        public boolean isWithinTolerance​(float value1,
                                         float value2)
        Description copied from interface: FloatingPointTolerance
        Indicates whether the specified values are equal under the tolerance.
        Specified by:
        isWithinTolerance in interface FloatingPointTolerance
        Parameters:
        value1 - the first value to compare
        value2 - the second value to compare
        Returns:
        true if the two values lie with the error bounds, otherwise false
      • isWithinTolerance

        public boolean isWithinTolerance​(double value1,
                                         double value2)
        Description copied from interface: FloatingPointTolerance
        Indicates whether the specified values are equal under the tolerance.
        Specified by:
        isWithinTolerance in interface FloatingPointTolerance
        Parameters:
        value1 - the first value to compare
        value2 - the second value to compare
        Returns:
        true if the two values lie with the error bounds, otherwise false
      • isWithinTolerance

        public boolean isWithinTolerance​(BigDecimal value1,
                                         BigDecimal value2)
        Indicates whether the specified values are equal under the tolerance.

        ULP based tolerance is not supported for BigDecimal values.

        Specified by:
        isWithinTolerance in interface FloatingPointTolerance
        Parameters:
        value1 - the first value to compare
        value2 - the second value to compare
        Returns:
        true if the two values lie with the error bounds, otherwise false
      • getMaxUlps

        public int getMaxUlps()
        Gets the maximum number of ULPs allowed between two values.
        Returns:
        the ULP distance bound