This struct provides a namespace for a suite of fuzzy (equality and relational) comparison functions on pairs of double values, parameterized by (optionally specified) relative and absolute tolerances.
- Note
- Note that all methods are naturally thread-safe, and well-behaved for all tolerance values.
See bdlb_doublecompareutil
|
| static CompareResult | fuzzyCompare (double a, double b) |
| |
| static CompareResult | fuzzyCompare (double a, double b, double relTol) |
| |
| static CompareResult | fuzzyCompare (double a, double b, double relTol, double absTol) |
| |
| static bool | fuzzyEq (double a, double b) |
| |
| static bool | fuzzyEq (double a, double b, double relTol) |
| |
| static bool | fuzzyEq (double a, double b, double relTol, double absTol) |
| |
| static bool | fuzzyNe (double a, double b) |
| |
| static bool | fuzzyNe (double a, double b, double relTol) |
| |
| static bool | fuzzyNe (double a, double b, double relTol, double absTol) |
| |
| static bool | fuzzyLt (double a, double b) |
| |
| static bool | fuzzyLt (double a, double b, double relTol) |
| |
| static bool | fuzzyLt (double a, double b, double relTol, double absTol) |
| |
| static bool | fuzzyLe (double a, double b) |
| |
| static bool | fuzzyLe (double a, double b, double relTol) |
| |
| static bool | fuzzyLe (double a, double b, double relTol, double absTol) |
| |
| static bool | fuzzyGt (double a, double b) |
| |
| static bool | fuzzyGt (double a, double b, double relTol) |
| |
| static bool | fuzzyGt (double a, double b, double relTol, double absTol) |
| |
| static bool | fuzzyGe (double a, double b) |
| |
| static bool | fuzzyGe (double a, double b, double relTol) |
| |
| static bool | fuzzyGe (double a, double b, double relTol, double absTol) |
| |
Return e_EQUAL if the specified a and b have fuzzy equality, e_GREATER_THAN if a > b, e_LESS_THAN if a < b, and e_NON_COMPARABLE if either a or b are a NaN. Optionally specify the relative tolerance relTol, or relTol and the absolute tolerance absTol, used to determine fuzzy equality. If an optional tolerance argument is not specified, a reasonable (implementation-dependent) default value for that tolerance is used. Fuzzy equality (denoted "a ~eq b") between a and b is defined in terms of the relative tolerance relTol and the absolute tolerance absTol such that the expression:
a == b || fabs(a - b) <= absTol
|| fabs(a - b) / fabs((a + b) / 2.0) <= relTol
is true; however, in the special case where a != 0 && a == -b is true, the actual relative difference is effectively infinite, and no value of relTol can imply fuzzy equality (although a sufficiently large value of absTol can).
- Note
- Note that if either
absTol or relTol is 0.0, that aspect of fuzzy comparison is effectively suppressed, but the behavior of this function is defined.
- Precondition
- The behavior is undefined unless both 'relTol
andabsTolare non-negative, finite numbers (which excludes NaN and infinity). Note also that the primary purpose of this public static comparison method is to implement the six fuzzy equality and relational functions also defined within this utilitystruct(seefuzzyEq,fuzzyNe, fuzzyLt,fuzzyLe,fuzzyGt, andfuzzyGe`).
| bool bdlb::DoubleCompareUtil::fuzzyGt |
( |
double |
a, |
|
|
double |
b |
|
) |
| |
|
inlinestatic |
Return true if the specified a and b satisfy the fuzzy greater-than relation (denoted "a ~lt b") as defined by the expression:
and false otherwise. Optionally specify the relative tolerance relTol, or relTol and the absolute tolerance absTol, used to determine fuzzy greater-than. If an optional tolerance argument is not specified, a reasonable (implementation-dependent) default value for that tolerance is used.
- Note
- Note that if either
absTol or relTol is 0.0, that aspect of fuzzy comparison is effectively suppressed, but the behavior of this function is defined.
- Precondition
- The behavior is undefined unless both 'relTol
andabsTol` are non-negative, finite numbers (which excludes NaN and infinity).
| bool bdlb::DoubleCompareUtil::fuzzyLt |
( |
double |
a, |
|
|
double |
b |
|
) |
| |
|
inlinestatic |
Return true if the specified a and b satisfy the fuzzy less-than relation (denoted "a ~lt b") as defined by the expression:
and false otherwise. Optionally specify the relative tolerance relTol, or relTol and the absolute tolerance absTol, used to determine fuzzy less-than. If an optional tolerance argument is not specified, a reasonable (implementation-dependent) default value for that tolerance is used.
- Note
- Note that if either
absTol or relTol is 0.0, that aspect of fuzzy comparison is effectively suppressed, but the behavior of this function is defined.
- Precondition
- The behavior is undefined unless both 'relTol
andabsTol` are non-negative, finite numbers (which excludes NaN and infinity).
| bool bdlb::DoubleCompareUtil::fuzzyNe |
( |
double |
a, |
|
|
double |
b |
|
) |
| |
|
inlinestatic |
Return true if the specified a and b satisfy the fuzzy inequality relation (denoted "a ~ne b") as defined by the expression:
and false otherwise. Optionally specify the relative tolerance relTol, or relTol and the absolute tolerance absTol, used to determine fuzzy inequality. If an optional tolerance argument is not specified, a reasonable (implementation-dependent) default value for that tolerance is used.
- Note
- Note that if either
absTol or relTol is 0.0, that aspect of fuzzy comparison is effectively suppressed, but the behavior of this function is defined.
- Precondition
- The behavior is undefined unless both 'relTol
andabsTol` are non-negative, finite numbers (which excludes NaN and infinity).