- java.lang.Object
-
- com.pervasive.datarush.operators.assertion.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.
-
-
Field Summary
-
Fields inherited from interface com.pervasive.datarush.operators.assertion.FloatingPointTolerance
EXACT
-
-
Constructor Summary
Constructors Constructor Description UlpDistanceBound(int maxUlps)
Define a fixed bound on the distance between two floating point values, measured in ULPs.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getMaxUlps()
Gets the maximum number of ULPs allowed between two values.boolean
isWithinTolerance(double value1, double value2)
Indicates whether the specified values are equal under the tolerance.boolean
isWithinTolerance(float value1, float value2)
Indicates whether the specified values are equal under the tolerance.boolean
isWithinTolerance(BigDecimal value1, BigDecimal value2)
Indicates whether the specified values are equal under the tolerance.
-
-
-
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
- ifepsilon
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 interfaceFloatingPointTolerance
- Parameters:
value1
- the first value to comparevalue2
- the second value to compare- Returns:
true
if the two values lie with the error bounds, otherwisefalse
-
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 interfaceFloatingPointTolerance
- Parameters:
value1
- the first value to comparevalue2
- the second value to compare- Returns:
true
if the two values lie with the error bounds, otherwisefalse
-
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 interfaceFloatingPointTolerance
- Parameters:
value1
- the first value to comparevalue2
- the second value to compare- Returns:
true
if the two values lie with the error bounds, otherwisefalse
-
getMaxUlps
public int getMaxUlps()
Gets the maximum number of ULPs allowed between two values.- Returns:
- the ULP distance bound
-
-