1#ifndef __COMMON_TRAITS_HPP__
2#define __COMMON_TRAITS_HPP__
8# define LIKELY(EXPR) __builtin_expect(!!(EXPR), 1)
10# define LIKELY(EXPR) (!!(EXPR))
14# define X_ASSERT(CHECK) void(0)
16# define X_ASSERT(CHECK) \
17 (LIKELY(CHECK) ? void(0) : [] { assert(!(#CHECK)); }())
27constexpr double tolerance_equality_float = 1e-15;
31 requires std::is_integral_v<std::remove_cvref_t<T>>;
32 requires !std::is_same_v<std::remove_cvref_t<T>,
bool>;
33 requires std::is_arithmetic_v<
decltype(n + 1)>;
34 requires !std::is_pointer_v<std::remove_cvref_t<T>>;
42template <NumberType T, NumberType U, NumberType Tol =
double>
44almost_equal(T val, U val2, Tol tolerance = tolerance_equality_float)
46 using CommonT = std::common_type_t<T, U>;
47 return std::abs(
static_cast<CommonT
>(val) -
static_cast<CommonT
>(val2))
48 <
static_cast<CommonT
>(tolerance);
52template <NumberType T, NumberType U, NumberType Tol =
double>
54almost_equal(
const T* val,
56 Tol tolerance = tolerance_equality_float)
58 if (val ==
nullptr || val2 ==
nullptr)
62 return almost_equal(*val, *val2, tolerance);