java.lang.Object
com.pervasive.datarush.operators.assertion.UlpDistanceBound
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionUlpDistanceBound(int maxUlps) Define a fixed bound on the distance between two floating point values, measured in ULPs. -
Method Summary
Modifier and TypeMethodDescriptionintGets the maximum number of ULPs allowed between two values.booleanisWithinTolerance(double value1, double value2) Indicates whether the specified values are equal under the tolerance.booleanisWithinTolerance(float value1, float value2) Indicates whether the specified values are equal under the tolerance.booleanisWithinTolerance(BigDecimal value1, BigDecimal value2) Indicates whether the specified values are equal under the tolerance.
-
Constructor Details
-
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- ifepsilonis negative.
-
-
Method Details
-
isWithinTolerance
public boolean isWithinTolerance(float value1, float value2) Description copied from interface:FloatingPointToleranceIndicates whether the specified values are equal under the tolerance.- Specified by:
isWithinTolerancein interfaceFloatingPointTolerance- Parameters:
value1- the first value to comparevalue2- the second value to compare- Returns:
trueif the two values lie with the error bounds, otherwisefalse
-
isWithinTolerance
public boolean isWithinTolerance(double value1, double value2) Description copied from interface:FloatingPointToleranceIndicates whether the specified values are equal under the tolerance.- Specified by:
isWithinTolerancein interfaceFloatingPointTolerance- Parameters:
value1- the first value to comparevalue2- the second value to compare- Returns:
trueif the two values lie with the error bounds, otherwisefalse
-
isWithinTolerance
Indicates whether the specified values are equal under the tolerance.ULP based tolerance is not supported for
BigDecimalvalues.- Specified by:
isWithinTolerancein interfaceFloatingPointTolerance- Parameters:
value1- the first value to comparevalue2- the second value to compare- Returns:
trueif 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
-