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)); }())
26constexpr double tolerance_equality_float = 1e-15;
30 requires std::is_integral_v<std::remove_cvref_t<T> >;
31 requires !std::is_same_v<std::remove_cvref_t<T>,
bool>;
32 requires std::is_arithmetic_v<
decltype(n + 1)>;
33 requires !std::is_pointer_v<std::remove_cvref_t<T> >;
40template <NumberType T>
42almost_equal(T val, T val2, T tolerance = tolerance_equality_float)
44 using CommonT = std::common_type_t<T, T>;
45 return std::abs(
static_cast<CommonT
>(val) -
static_cast<CommonT
>(val2))
46 <
static_cast<CommonT
>(tolerance);
50template <NumberType T>
52almost_equal(
const T& val,
54 T tolerance = tolerance_equality_float)
56 using CommonT = std::common_type_t<T, T>;
57 return std::abs(
static_cast<CommonT
>(val) -
static_cast<CommonT
>(val2))
58 <
static_cast<CommonT
>(tolerance);
62template <NumberType T>
64almost_equal(
const T* val,
66 T tolerance = tolerance_equality_float)
72 using CommonT = std::common_type_t<T, T>;
73 return std::abs(
static_cast<CommonT
>(*val) -
static_cast<CommonT
>(*val2))
74 <
static_cast<CommonT
>(tolerance);
78template <NumberType T>
80almost_equal(T&& val, T&& val2, T tolerance = tolerance_equality_float)
82 using CommonT = std::common_type_t<T, T>;
83 return std::abs(
static_cast<CommonT
>(val) -
static_cast<CommonT
>(val2))
84 <
static_cast<CommonT
>(tolerance);