1#ifndef __COMMON_TRAITS_HPP__
2#define __COMMON_TRAITS_HPP__
7# define LIKELY(EXPR) __builtin_expect(!!(EXPR), 1)
9# define LIKELY(EXPR) (!!(EXPR))
13# define X_ASSERT(CHECK) void(0)
15# define X_ASSERT(CHECK) \
16 ( LIKELY(CHECK) ? void(0) : []{assert(!#CHECK);}() )
22constexpr double tolerance_equality_float = 1e-15;
26 requires std::is_integral_v<std::remove_cvref_t<T>>;
27 requires !std::is_same_v<std::remove_cvref_t<T>,
bool>;
28 requires std::is_arithmetic_v<
decltype(n + 1)>;
29 requires !std::is_pointer_v<std::remove_cvref_t<T>>;
36template <NumberType T>
37inline bool almost_equal(T val, T val2, T tolerance = tolerance_equality_float)
39 using CommonT = std::common_type_t<T, T>;
40 return std::abs(
static_cast<CommonT
>(val) -
static_cast<CommonT
>(val2)) <
41 static_cast<CommonT
>(tolerance);
45template <NumberType T>
46inline bool almost_equal(
const T& val,
const T& val2, T tolerance = tolerance_equality_float)
48 using CommonT = std::common_type_t<T, T>;
49 return std::abs(
static_cast<CommonT
>(val) -
static_cast<CommonT
>(val2)) <
50 static_cast<CommonT
>(tolerance);
54template <NumberType T>
55inline bool almost_equal(
const T* val,
const T* val2, T tolerance = tolerance_equality_float)
61 using CommonT = std::common_type_t<T, T>;
62 return std::abs(
static_cast<CommonT
>(*val) -
static_cast<CommonT
>(*val2)) <
63 static_cast<CommonT
>(tolerance);
67template <NumberType T>
68inline bool almost_equal(T&& val, T&& val2, T tolerance = tolerance_equality_float)
70 using CommonT = std::common_type_t<T, T>;
71 return std::abs(
static_cast<CommonT
>(val) -
static_cast<CommonT
>(val2)) <
72 static_cast<CommonT
>(tolerance);