13 #ifndef INCLUDE_MOLASSEMBLER_TEMPLTE_CONSTEXPR_FP_COMPARISON_H
14 #define INCLUDE_MOLASSEMBLER_TEMPLTE_CONSTEXPR_FP_COMPARISON_H
22 namespace Molassembler {
30 constexpr std::enable_if_t<
31 std::is_floating_point<T>::value,
40 constexpr std::enable_if_t<
41 std::is_floating_point<T>::value,
54 constexpr std::enable_if_t<
55 std::is_floating_point<T>::value,
57 > isCloseRelativeOrAbsolute(
66 std::is_floating_point<T>::value,
68 > isCloseRelativeOrAbsolute(
71 const T relativeTolerance,
72 const T absoluteTolerance
75 a != std::numeric_limits<T>::infinity()
76 && a != - std::numeric_limits<T>::infinity()
77 && b != std::numeric_limits<T>::infinity()
78 && b != - std::numeric_limits<T>::infinity()
82 throw "isCloseRelativeOrAbsolute cannot handle infinities or NaNs!";
85 if(!(relativeTolerance >= 0 && absoluteTolerance >= 0)) {
86 throw "isCloseRelativeOrAbsolute: One of either tolerances "
87 "needs to be above zero!";
93 relativeTolerance * Math::max(
106 std::is_floating_point<T>::value,
111 const T relativeTolerance
113 return Detail::isCloseRelativeOrAbsolute(
123 std::is_floating_point<T>::value,
128 const T absoluteTolerance
130 return Detail::isCloseRelativeOrAbsolute(
143 const T absoluteTolerance_;
147 : absoluteTolerance_(absoluteTolerance)
150 absoluteTolerance > 0
151 && absoluteTolerance != std::numeric_limits<T>::infinity()
152 && absoluteTolerance == absoluteTolerance
156 constexpr
bool isLessThan(
const T a,
const T b)
const noexcept {
157 return a < (b - absoluteTolerance_);
160 constexpr
bool isMoreThan(
const T a,
const T b)
const noexcept {
161 return a > (b + absoluteTolerance_);
164 constexpr
bool isLessOrEqual(
const T a,
const T b)
const noexcept {
165 return a < (b + absoluteTolerance_);
168 constexpr
bool isMoreOrEqual(
const T a,
const T b)
const noexcept {
169 return a > (b - absoluteTolerance_);
172 constexpr
bool isEqual(
const T a,
const T b)
const noexcept {
173 return Math::abs(a - b) <= absoluteTolerance_;
176 constexpr
bool isUnequal(
const T a,
const T b)
const noexcept {
177 return !isEqual(a, b);
181 constexpr
bool operator () (
const T a,
const T b)
const noexcept {
182 return isEqual(a, b);
189 const T relativeTolerance_;
193 : relativeTolerance_(relativeTolerance)
195 assert(relativeTolerance > 0);
198 constexpr
bool isLessThan(
const T a,
const T b)
const {
200 (a < b) && !Detail::isCloseRelativeOrAbsolute(
209 constexpr
bool isMoreThan(
const T a,
const T b)
const {
211 (a > b) && !Detail::isCloseRelativeOrAbsolute(
220 constexpr
bool isLessOrEqual(
const T a,
const T b)
const {
222 (a < b) || Detail::isCloseRelativeOrAbsolute(
231 constexpr
bool isMoreOrEqual(
const T a,
const T b)
const {
233 (a > b) || Detail::isCloseRelativeOrAbsolute(
242 constexpr
bool isEqual(
const T a,
const T b)
const {
243 return Detail::isCloseRelativeOrAbsolute(
251 constexpr
bool isUnequal(
const T a,
const T b)
const {
252 return !Detail::isCloseRelativeOrAbsolute(
261 constexpr
bool operator () (
const T a,
const T b)
const noexcept {
262 return isEqual(a, b);
constexpr math implementations
constexpr bool operator()(const T a, const T b) const noexcept
Function call operator compares equality.
Definition: FloatingPointComparison.h:181
Definition: FloatingPointComparison.h:187
Definition: FloatingPointComparison.h:141
#define PURITY_STRONG
Definition: Preprocessor.h:65
constexpr bool operator()(const T a, const T b) const noexcept
Function call operator compares equality.
Definition: FloatingPointComparison.h:261