5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MATH_ULP_TOLERANCE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MATH_ULP_TOLERANCE_HPP_
12#include "arene/base/stdlib_choice/enable_if.hpp"
13#include "arene/base/stdlib_choice/is_integral.hpp"
14#include "arene/base/stdlib_choice/make_signed.hpp"
22namespace ulp_tolerance_detail {
26template <
typename UlpCount>
27class ulp_tolerance_comparator {
34 constexpr explicit ulp_tolerance_comparator(UlpCount tol) noexcept
39 constexpr auto tolerance() const noexcept -> UlpCount {
return tolerance_; }
46 template <
typename T, constra
ints<std::enable_if_t<::arene::base::enable_ulp_distance_comparable<T>>> =
nullptr>
47 constexpr auto operator()(T left, T right)
const noexcept ->
bool {
49 if (distance_result.has_error()) {
56 return cmp_less_equal(math::abs(*distance_result), tolerance_);
62class ulp_tolerance_comparator_factory {
69 template <typename UlpCount, constraints<std::enable_if_t<std::is_integral<UlpCount>::value>> =
nullptr>
70 constexpr auto operator()(UlpCount tolerance)
const noexcept -> ulp_tolerance_comparator<UlpCount> {
71 return ulp_tolerance_comparator<UlpCount>(tolerance);
#define ARENE_CPP14_INLINE_VARIABLE(type, name)
Emulates C++17's inline variable declarations for function objects.
Definition cpp14_inline.hpp:69
Definition accumulate.hpp:37
constexpr auto ulp_distance
Compute the distance in units in the last place between two floating-point values.
Definition accumulate.hpp:36
Provides backports of the safe integer comparison functions from C++20.