crypto_trader
Cryptocurrency Trading Bot API Documentation
Loading...
Searching...
No Matches
crypto_trader::common::Math Class Reference

Provides static utility methods for safe floating-point comparisons. More...

#include <math.h>

Collaboration diagram for crypto_trader::common::Math:
Collaboration graph

Static Public Member Functions

static bool isEqual (double a, double b, double relEpsilon=DEFAULT_REL_EPSILON, double absEpsilon=DEFAULT_ABS_EPSILON)
 Checks if two double-precision floating-point numbers are considered equal within a specified relative and/or absolute tolerance.
static bool isNotEqual (double a, double b, double relEpsilon=DEFAULT_REL_EPSILON, double absEpsilon=DEFAULT_ABS_EPSILON)
 Checks if two double-precision floating-point numbers are considered not equal.
static bool isLess (double a, double b, double relEpsilon=DEFAULT_REL_EPSILON, double absEpsilon=DEFAULT_ABS_EPSILON)
 Checks if the first double value is strictly less than the second, considering floating-point tolerance.
static bool isGreater (double a, double b, double relEpsilon=DEFAULT_REL_EPSILON, double absEpsilon=DEFAULT_ABS_EPSILON)
 Checks if the first double value is strictly greater than the second, considering floating-point tolerance.
static bool isLessOrEqual (double a, double b, double relEpsilon=DEFAULT_REL_EPSILON, double absEpsilon=DEFAULT_ABS_EPSILON)
 Checks if the first double value is less than or equal to the second, considering floating-point tolerance.
static bool isGreaterOrEqual (double a, double b, double relEpsilon=DEFAULT_REL_EPSILON, double absEpsilon=DEFAULT_ABS_EPSILON)
 Checks if the first double value is greater than or equal to the second, considering floating-point tolerance.
static bool isZero (double a, double absEpsilon=DEFAULT_ABS_EPSILON)
 Checks if a double value is effectively zero within an absolute tolerance.

Static Public Attributes

static constexpr double DEFAULT_REL_EPSILON = 1e-9
 Default relative epsilon for comparisons.
static constexpr double DEFAULT_ABS_EPSILON = 1e-12
 Default absolute epsilon for comparisons near zero.

Detailed Description

Provides static utility methods for safe floating-point comparisons.

This class implements a hybrid comparison approach (relative and absolute epsilon) to account for the inherent imprecision of floating-point numbers across different scales.

Member Function Documentation

◆ isEqual()

bool crypto_trader::common::Math::isEqual ( double a,
double b,
double relEpsilon = DEFAULT_REL_EPSILON,
double absEpsilon = DEFAULT_ABS_EPSILON )
inlinestatic

Checks if two double-precision floating-point numbers are considered equal within a specified relative and/or absolute tolerance.

Parameters
aThe first double value.
bThe second double value.
relEpsilonThe relative epsilon value. Defaults to DEFAULT_REL_EPSILON.
absEpsilonThe absolute epsilon value. Defaults to DEFAULT_ABS_EPSILON.
Returns
True if the numbers are considered equal, false otherwise.

◆ isGreater()

bool crypto_trader::common::Math::isGreater ( double a,
double b,
double relEpsilon = DEFAULT_REL_EPSILON,
double absEpsilon = DEFAULT_ABS_EPSILON )
inlinestatic

Checks if the first double value is strictly greater than the second, considering floating-point tolerance.

Parameters
aThe first double value.
bThe second double value.
relEpsilonThe relative epsilon value. Defaults to DEFAULT_REL_EPSILON.
absEpsilonThe absolute epsilon value. Defaults to DEFAULT_ABS_EPSILON.
Returns
True if 'a' is strictly greater than 'b' outside the equality zone, false otherwise.

◆ isGreaterOrEqual()

bool crypto_trader::common::Math::isGreaterOrEqual ( double a,
double b,
double relEpsilon = DEFAULT_REL_EPSILON,
double absEpsilon = DEFAULT_ABS_EPSILON )
inlinestatic

Checks if the first double value is greater than or equal to the second, considering floating-point tolerance.

Parameters
aThe first double value.
bThe second double value.
relEpsilonThe relative epsilon value. Defaults to DEFAULT_REL_EPSILON.
absEpsilonThe absolute epsilon value. Defaults to DEFAULT_ABS_EPSILON.
Returns
True if 'a' is greater than or equal to 'b', false otherwise.

◆ isLess()

bool crypto_trader::common::Math::isLess ( double a,
double b,
double relEpsilon = DEFAULT_REL_EPSILON,
double absEpsilon = DEFAULT_ABS_EPSILON )
inlinestatic

Checks if the first double value is strictly less than the second, considering floating-point tolerance.

Parameters
aThe first double value.
bThe second double value.
relEpsilonThe relative epsilon value. Defaults to DEFAULT_REL_EPSILON.
absEpsilonThe absolute epsilon value. Defaults to DEFAULT_ABS_EPSILON.
Returns
True if 'a' is strictly less than 'b' outside the equality zone, false otherwise.

◆ isLessOrEqual()

bool crypto_trader::common::Math::isLessOrEqual ( double a,
double b,
double relEpsilon = DEFAULT_REL_EPSILON,
double absEpsilon = DEFAULT_ABS_EPSILON )
inlinestatic

Checks if the first double value is less than or equal to the second, considering floating-point tolerance.

Parameters
aThe first double value.
bThe second double value.
relEpsilonThe relative epsilon value. Defaults to DEFAULT_REL_EPSILON.
absEpsilonThe absolute epsilon value. Defaults to DEFAULT_ABS_EPSILON.
Returns
True if 'a' is less than or equal to 'b', false otherwise.

◆ isNotEqual()

bool crypto_trader::common::Math::isNotEqual ( double a,
double b,
double relEpsilon = DEFAULT_REL_EPSILON,
double absEpsilon = DEFAULT_ABS_EPSILON )
inlinestatic

Checks if two double-precision floating-point numbers are considered not equal.

Parameters
aThe first double value.
bThe second double value.
relEpsilonThe relative epsilon value. Defaults to DEFAULT_REL_EPSILON.
absEpsilonThe absolute epsilon value. Defaults to DEFAULT_ABS_EPSILON.
Returns
True if the numbers are considered not equal, false otherwise.

◆ isZero()

bool crypto_trader::common::Math::isZero ( double a,
double absEpsilon = DEFAULT_ABS_EPSILON )
inlinestatic

Checks if a double value is effectively zero within an absolute tolerance.

Parameters
aThe double value to check.
absEpsilonThe absolute epsilon value. Defaults to DEFAULT_ABS_EPSILON.
Returns
True if the number is considered zero, false otherwise.

Member Data Documentation

◆ DEFAULT_ABS_EPSILON

double crypto_trader::common::Math::DEFAULT_ABS_EPSILON = 1e-12
staticconstexpr

Default absolute epsilon for comparisons near zero.

◆ DEFAULT_REL_EPSILON

double crypto_trader::common::Math::DEFAULT_REL_EPSILON = 1e-9
staticconstexpr

Default relative epsilon for comparisons.


The documentation for this class was generated from the following file:
  • /home/runner/work/crypto_trader/crypto_trader/common/math.h