LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar::util::RealComparisons< RealType > Struct Template Reference

Provides simple real number checks. More...

#include "RealComparisons.h"

Public Types

using Value_t = RealType
 

Public Member Functions

constexpr RealComparisons (Value_t threshold)
 type of values being compered More...
 
constexpr bool zero (Value_t value) const
 Returns whether the value is no farther from 0 than the threshold. More...
 
constexpr bool nonZero (Value_t value) const
 Returns whether the value is farther from 0 than the threshold. More...
 
constexpr bool equal (Value_t a, Value_t b) const
 Returns whether a and b are no farther than the threshold. More...
 
constexpr bool nonEqual (Value_t a, Value_t b) const
 Returns whether a and b are farther than the threshold. More...
 
constexpr bool strictlyNegative (Value_t value) const
 Returns whether value is larger than zero beyond tolerance. More...
 
constexpr bool strictlyPositive (Value_t value) const
 Returns whether value is smaller than zero beyond tolerance. More...
 
constexpr bool nonNegative (Value_t value) const
 Returns whether value is larger than or equal() to zero. More...
 
constexpr bool nonPositive (Value_t value) const
 Returns whether value is smaller than or equal() to zero. More...
 
constexpr bool strictlySmaller (Value_t a, Value_t b) const
 Returns whether a is strictly smaller than b. More...
 
constexpr bool nonSmaller (Value_t a, Value_t b) const
 Returns whether a is greater than (or equal to) b. More...
 
constexpr bool strictlyGreater (Value_t a, Value_t b) const
 Returns whether a is strictly greater than b. More...
 
constexpr bool nonGreater (Value_t a, Value_t b) const
 Returns whether a is smaller than (or equal to) b. More...
 
constexpr bool within (Value_t value, Value_t lower, Value_t upper) const
 Returns whether value is between the bounds (included) More...
 
constexpr bool withinSorted (Value_t value, Value_t lower, Value_t upper) const
 Returns whether value is between bounds (included); bounds are sorted. More...
 

Public Attributes

Value_t threshold
 

Detailed Description

template<typename RealType>
struct lar::util::RealComparisons< RealType >

Provides simple real number checks.


Template Parameters
RealTypetype of value to operate on

This class provides some members to perform comparisons between real numbers, allowing for some tolerance for rounding errors.

The tolerance parameter is fixed. Example of usage:

double const sqrt2 = std::sqrt(2);
// it should print the message
if (check.equal(sqrt2, 1.4142)) {
std::cout
<< "Square root of 2 is not even close to 1.4142." << std::endl;
}
// it should not print the message
if (check.equal(sqrt2, 1.414213)) {
std::cout
<< "Square root of 2 is not even close to 1.414213." << std::endl;
}
// this should print the message
if (check.within(std::sqrt(2), 0., 1.41421)) {
std::cout
<< "Square root of 2 is between 0 and 1.41421 (tops)." << std::endl;
}
// this will probably print the message
double const epsilon = 2.0 - (sqrt2 * sqrt2);
if (check.zero(epsilon)) {
std::cout
<< "The square of the square root of 2 is roughly 2." << std::endl;
}

Definition at line 65 of file RealComparisons.h.

Member Typedef Documentation

template<typename RealType>
using lar::util::RealComparisons< RealType >::Value_t = RealType

Definition at line 66 of file RealComparisons.h.

Constructor & Destructor Documentation

template<typename RealType>
constexpr lar::util::RealComparisons< RealType >::RealComparisons ( Value_t  threshold)
inline

type of values being compered

Constructor: specify the threshold

Definition at line 69 of file RealComparisons.h.

Member Function Documentation

template<typename RealType>
constexpr bool lar::util::RealComparisons< RealType >::equal ( Value_t  a,
Value_t  b 
) const
inline

Returns whether a and b are no farther than the threshold.

Definition at line 78 of file RealComparisons.h.

References lar::util::RealComparisons< RealType >::zero().

Referenced by detectGlobalDriftDir(), lar::util::RealComparisons< RealType >::nonEqual(), lar::util::Vector2DComparison< typename Comp_t::Value_t >::nonEqual(), lar::util::Vector3DComparison< RealType >::nonEqual(), and geo::OpDetGeo::PrintOpDetInfo().

78 { return zero(a - b); }
constexpr bool zero(Value_t value) const
Returns whether the value is no farther from 0 than the threshold.
template<typename RealType>
constexpr bool lar::util::RealComparisons< RealType >::nonEqual ( Value_t  a,
Value_t  b 
) const
inline

Returns whether a and b are farther than the threshold.

Definition at line 81 of file RealComparisons.h.

References lar::util::RealComparisons< RealType >::equal().

Referenced by checkTPCcoords(), geo::AuxDetSensitiveGeo::PrintAuxDetInfo(), and geo::AuxDetGeo::PrintAuxDetInfo().

81 { return !equal(a, b); }
constexpr bool equal(Value_t a, Value_t b) const
Returns whether a and b are no farther than the threshold.
template<typename RealType>
constexpr bool lar::util::RealComparisons< RealType >::nonGreater ( Value_t  a,
Value_t  b 
) const
inline

Returns whether a is smaller than (or equal to) b.

Definition at line 105 of file RealComparisons.h.

References lar::util::RealComparisons< RealType >::nonPositive().

105 { return nonPositive(a - b); }
constexpr bool nonPositive(Value_t value) const
Returns whether value is smaller than or equal() to zero.
template<typename RealType>
constexpr bool lar::util::RealComparisons< RealType >::nonNegative ( Value_t  value) const
inline
template<typename RealType>
constexpr bool lar::util::RealComparisons< RealType >::nonPositive ( Value_t  value) const
inline

Returns whether value is smaller than or equal() to zero.

Definition at line 93 of file RealComparisons.h.

References lar::util::RealComparisons< RealType >::threshold.

Referenced by lar::util::RealComparisons< RealType >::nonGreater(), and lar::util::RealComparisons< RealType >::within().

93 { return value <= threshold; }
double value
Definition: spectrum.C:18
template<typename RealType>
constexpr bool lar::util::RealComparisons< RealType >::nonSmaller ( Value_t  a,
Value_t  b 
) const
inline

Returns whether a is greater than (or equal to) b.

Definition at line 99 of file RealComparisons.h.

References lar::util::RealComparisons< RealType >::nonNegative().

Referenced by groupTPCsByRangeCoord(), and makeGridPartition().

99 { return nonNegative(a - b); }
constexpr bool nonNegative(Value_t value) const
Returns whether value is larger than or equal() to zero.
template<typename RealType>
constexpr bool lar::util::RealComparisons< RealType >::nonZero ( Value_t  value) const
inline

Returns whether the value is farther from 0 than the threshold.

Definition at line 75 of file RealComparisons.h.

References lar::util::RealComparisons< RealType >::zero().

Referenced by geo::OpDetGeo::PrintOpDetInfo().

75 { return !zero(value); }
constexpr bool zero(Value_t value) const
Returns whether the value is no farther from 0 than the threshold.
double value
Definition: spectrum.C:18
template<typename RealType>
constexpr bool lar::util::RealComparisons< RealType >::strictlyGreater ( Value_t  a,
Value_t  b 
) const
inline

Returns whether a is strictly greater than b.

Definition at line 102 of file RealComparisons.h.

References lar::util::RealComparisons< RealType >::strictlyPositive().

Referenced by makeGridPartition().

102 { return strictlyPositive(a - b); }
constexpr bool strictlyPositive(Value_t value) const
Returns whether value is smaller than zero beyond tolerance.
template<typename RealType>
constexpr bool lar::util::RealComparisons< RealType >::strictlyNegative ( Value_t  value) const
inline

Returns whether value is larger than zero beyond tolerance.

Definition at line 84 of file RealComparisons.h.

References lar::util::RealComparisons< RealType >::threshold.

Referenced by lar::util::RealComparisons< RealType >::strictlySmaller().

84 { return value < -threshold; }
double value
Definition: spectrum.C:18
template<typename RealType>
constexpr bool lar::util::RealComparisons< RealType >::strictlyPositive ( Value_t  value) const
inline

Returns whether value is smaller than zero beyond tolerance.

Definition at line 87 of file RealComparisons.h.

References lar::util::RealComparisons< RealType >::threshold.

Referenced by lar::util::RealComparisons< RealType >::strictlyGreater().

87 { return value > threshold; }
double value
Definition: spectrum.C:18
template<typename RealType>
constexpr bool lar::util::RealComparisons< RealType >::strictlySmaller ( Value_t  a,
Value_t  b 
) const
inline

Returns whether a is strictly smaller than b.

Definition at line 96 of file RealComparisons.h.

References lar::util::RealComparisons< RealType >::strictlyNegative().

Referenced by makeGridPartition().

96 { return strictlyNegative(a - b); }
constexpr bool strictlyNegative(Value_t value) const
Returns whether value is larger than zero beyond tolerance.
template<typename RealType>
constexpr bool lar::util::RealComparisons< RealType >::within ( Value_t  value,
Value_t  lower,
Value_t  upper 
) const
inline

Returns whether value is between the bounds (included)

Definition at line 108 of file RealComparisons.h.

References lar::util::RealComparisons< RealType >::nonNegative(), and lar::util::RealComparisons< RealType >::nonPositive().

Referenced by lar::util::RealComparisons< RealType >::withinSorted().

109  {
110  return nonNegative(value - lower) && nonPositive(value - upper);
111  }
double value
Definition: spectrum.C:18
constexpr bool nonNegative(Value_t value) const
Returns whether value is larger than or equal() to zero.
constexpr bool nonPositive(Value_t value) const
Returns whether value is smaller than or equal() to zero.
template<typename RealType>
constexpr bool lar::util::RealComparisons< RealType >::withinSorted ( Value_t  value,
Value_t  lower,
Value_t  upper 
) const
inline

Returns whether value is between bounds (included); bounds are sorted.

Definition at line 114 of file RealComparisons.h.

References lar::util::RealComparisons< RealType >::within().

115  {
116  return (lower < upper) ? within(value, lower, upper) : within(value, upper, lower);
117  } // sortedWithin
double value
Definition: spectrum.C:18
constexpr bool within(Value_t value, Value_t lower, Value_t upper) const
Returns whether value is between the bounds (included)
template<typename RealType>
constexpr bool lar::util::RealComparisons< RealType >::zero ( Value_t  value) const
inline

Member Data Documentation


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