BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlb::DoubleCompareUtil Struct Reference

#include <bdlb_doublecompareutil.h>

Detailed Description

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

Public Types

enum  CompareResult { e_EQUAL = 0 , e_GREATER_THAN = 1 , e_LESS_THAN = -1 , e_NON_COMPARABLE = -127 }
 

Static Public Member Functions

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)
 

Static Public Attributes

static const double k_DEFAULT_RELATIVE_TOLERANCE
 
static const double k_DEFAULT_ABSOLUTE_TOLERANCE
 

Member Enumeration Documentation

◆ CompareResult

Enumerator
e_EQUAL 
e_GREATER_THAN 
e_LESS_THAN 
e_NON_COMPARABLE 

Member Function Documentation

◆ fuzzyCompare() [1/3]

DoubleCompareUtil::CompareResult bdlb::DoubleCompareUtil::fuzzyCompare ( double  a,
double  b 
)
inlinestatic

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 'relTolandabsTolare 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`).

◆ fuzzyCompare() [2/3]

DoubleCompareUtil::CompareResult bdlb::DoubleCompareUtil::fuzzyCompare ( double  a,
double  b,
double  relTol 
)
inlinestatic

◆ fuzzyCompare() [3/3]

static CompareResult bdlb::DoubleCompareUtil::fuzzyCompare ( double  a,
double  b,
double  relTol,
double  absTol 
)
static

◆ fuzzyEq() [1/3]

bool bdlb::DoubleCompareUtil::fuzzyEq ( double  a,
double  b 
)
inlinestatic

Return true if the specified a and b satisfy the fuzzy equality relation (denoted "a ~eq b") as defined by the expression:

fuzzyCompare(a, b, relTol, absTol) == e_EQUAL
@ e_EQUAL
Definition bdlb_doublecompareutil.h:280
static CompareResult fuzzyCompare(double a, double b)
Definition bdlb_doublecompareutil.h:465

and false otherwise. 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.

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 'relTolandabsTol` are non-negative, finite numbers (which excludes NaN and infinity).

◆ fuzzyEq() [2/3]

bool bdlb::DoubleCompareUtil::fuzzyEq ( double  a,
double  b,
double  relTol 
)
inlinestatic

◆ fuzzyEq() [3/3]

bool bdlb::DoubleCompareUtil::fuzzyEq ( double  a,
double  b,
double  relTol,
double  absTol 
)
inlinestatic

◆ fuzzyGe() [1/3]

bool bdlb::DoubleCompareUtil::fuzzyGe ( double  a,
double  b 
)
inlinestatic

Return true if the specified a and b satisfy the fuzzy greater-equal relation (denoted "a ~ge b") as defined by the expression:

fuzzyCompare(a, b, relTol, absTol) == e_GREATER_THAN or == e_EQUAL
@ e_GREATER_THAN
Definition bdlb_doublecompareutil.h:281

and false otherwise. Optionally specify the relative tolerance relTol, or relTol and the absolute tolerance absTol, used to determine fuzzy greater-equal. 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 'relTolandabsTol` are non-negative, finite numbers (which excludes NaN and infinity).

◆ fuzzyGe() [2/3]

bool bdlb::DoubleCompareUtil::fuzzyGe ( double  a,
double  b,
double  relTol 
)
inlinestatic

◆ fuzzyGe() [3/3]

bool bdlb::DoubleCompareUtil::fuzzyGe ( double  a,
double  b,
double  relTol,
double  absTol 
)
inlinestatic

◆ fuzzyGt() [1/3]

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:

fuzzyCompare(a, b, relTol, absTol) == e_GREATER_THAN

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 'relTolandabsTol` are non-negative, finite numbers (which excludes NaN and infinity).

◆ fuzzyGt() [2/3]

bool bdlb::DoubleCompareUtil::fuzzyGt ( double  a,
double  b,
double  relTol 
)
inlinestatic

◆ fuzzyGt() [3/3]

bool bdlb::DoubleCompareUtil::fuzzyGt ( double  a,
double  b,
double  relTol,
double  absTol 
)
inlinestatic

◆ fuzzyLe() [1/3]

bool bdlb::DoubleCompareUtil::fuzzyLe ( double  a,
double  b 
)
inlinestatic

Return true if the specified a and b satisfy the fuzzy less-equal relation (denoted "a ~le b") as defined by the expression:

fuzzyCompare(a, b, relTol, absTol) == e_LESS_THAN or == e_EQUAL
@ e_LESS_THAN
Definition bdlb_doublecompareutil.h:282

and false otherwise. Optionally specify the relative tolerance relTol, or relTol and the absolute tolerance absTol, used to determine fuzzy less-equal. 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 'relTolandabsTol` are non-negative, finite numbers (which excludes NaN and infinity).

◆ fuzzyLe() [2/3]

bool bdlb::DoubleCompareUtil::fuzzyLe ( double  a,
double  b,
double  relTol 
)
inlinestatic

◆ fuzzyLe() [3/3]

bool bdlb::DoubleCompareUtil::fuzzyLe ( double  a,
double  b,
double  relTol,
double  absTol 
)
inlinestatic

◆ fuzzyLt() [1/3]

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:

fuzzyCompare(a, b, relTol, absTol) == e_LESS_THAN

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 'relTolandabsTol` are non-negative, finite numbers (which excludes NaN and infinity).

◆ fuzzyLt() [2/3]

bool bdlb::DoubleCompareUtil::fuzzyLt ( double  a,
double  b,
double  relTol 
)
inlinestatic

◆ fuzzyLt() [3/3]

bool bdlb::DoubleCompareUtil::fuzzyLt ( double  a,
double  b,
double  relTol,
double  absTol 
)
inlinestatic

◆ fuzzyNe() [1/3]

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:

fuzzyCompare(a, b, relTol, absTol) != e_EQUAL

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 'relTolandabsTol` are non-negative, finite numbers (which excludes NaN and infinity).

◆ fuzzyNe() [2/3]

bool bdlb::DoubleCompareUtil::fuzzyNe ( double  a,
double  b,
double  relTol 
)
inlinestatic

◆ fuzzyNe() [3/3]

bool bdlb::DoubleCompareUtil::fuzzyNe ( double  a,
double  b,
double  relTol,
double  absTol 
)
inlinestatic

Member Data Documentation

◆ k_DEFAULT_ABSOLUTE_TOLERANCE

const double bdlb::DoubleCompareUtil::k_DEFAULT_ABSOLUTE_TOLERANCE
static

◆ k_DEFAULT_RELATIVE_TOLERANCE

const double bdlb::DoubleCompareUtil::k_DEFAULT_RELATIVE_TOLERANCE
static

The documentation for this struct was generated from the following file: