- java.lang.Object
-
- com.pervasive.datarush.operators.assertion.RelativeErrorBound
-
- All Implemented Interfaces:
FloatingPointTolerance
public class RelativeErrorBound extends Object implements FloatingPointTolerance
Checks equivalence based on the relative error between two floating point numbers. Two values are considered equal if this error is less than a fixed bound.Specifically, for two values
v1
andv2
wherev1 > v2
and a non-negative bounde
, it is checked whetherMath.abs((v1 - v2)/v1) <= e
-
-
Field Summary
-
Fields inherited from interface com.pervasive.datarush.operators.assertion.FloatingPointTolerance
EXACT
-
-
Constructor Summary
Constructors Constructor Description RelativeErrorBound(double epsilon)
Define a fixed bound on the relative error of two floating point numbers.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
getEpsilon()
Gets the maximum percentage difference 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
-
RelativeErrorBound
public RelativeErrorBound(double epsilon)
Define a fixed bound on the relative error of two floating point numbers.- Parameters:
epsilon
- the fixed bound on the error- 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)
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
-
getEpsilon
public double getEpsilon()
Gets the maximum percentage difference allowed between two values.- Returns:
- the relative error bound
-
-