29 template <
typename... Args>
34template <
typename T, std::enable_if_t<std::is_
unsigned_v<T>,
bool> = true>
36 return bits >= std::numeric_limits<T>::digits ?
static_cast<T
>(-1) : (
static_cast<T
>(1) << bits) - 1;
40template <
typename T, std::enable_if_t<std::is_
floating_po
int_v<T>,
bool> = true>
42template <
typename T, std::enable_if_t<std::is_
floating_po
int_v<T>,
bool> = true>
46template <
typename T, std::enable_if_t<std::is_
floating_po
int_v<T>,
bool> = true>
48 if (!std::isfinite(t))
51 std::memcpy(&u, &t,
sizeof(T));
53 std::memcpy(&t, &u,
sizeof(T));
58template <
typename T, std::enable_if_t<std::is_
floating_po
int_v<T>,
bool> = true>
60 return std::fabs(
x) <= std::numeric_limits<T>::epsilon()
61 ? std::copysign(std::numeric_limits<T>::max(),
x)
62 :
static_cast<T
>(1.) /
x;
68#if defined(_MSC_VER) && !defined(__clang__)
69#pragma float_control(push)
70#pragma float_control(precise, off)
71#pragma fp_contract(on)
73template <
typename T, std::enable_if_t<std::is_
floating_po
int_v<T>,
bool> = true>
76 return std::fma(
a,
b,
c);
77#elif defined(__clang__)
82#if defined(_MSC_VER) && !defined(__clang__)
83#pragma float_control(pop)
87template <
size_t Begin,
size_t End,
typename F>
89 if constexpr (Begin < End) {
91 static_for<Begin + 1, End>(std::forward<F>(
f));
96template <
typename T, std::enable_if_t<std::is_
unsigned_v<T>,
bool> = true>
103template <
typename T, std::enable_if_t<std::is_
unsigned_v<T>,
bool> = true>
105 constexpr size_t bit_count =
sizeof(T) * CHAR_BIT;
107 auto mask =
static_cast<T
>(-1) >> (bit_count / 2);
109 for (
size_t i = log_bits - 1,
n =
size_t{1} << i; i > 0; --i,
n >>= 1) {
117template <
typename T, std::enable_if_t<std::is_
unsigned_v<T>,
bool> = true>
126 auto prev_value = atomic;
127 while (prev_value <
value && !atomic.compare_exchange_weak(prev_value,
value));
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
BVH_ALWAYS_INLINE T split_bits(T x)
Split an unsigned integer such that its bits are spaced by 2 zeros.
constexpr T round_up_log2(T i, T p=0)
Computes the (rounded-up) compile-time log in base-2 of an unsigned integer.
typename UnsignedInt< Bits >::Type UnsignedIntType
BVH_ALWAYS_INLINE T safe_inverse(T x)
Computes the inverse of the given value, always returning a finite value.
BVH_ALWAYS_INLINE T morton_encode(T x, T y, T z)
Morton-encode three unsigned integers into one.
BVH_ALWAYS_INLINE T add_ulp_magnitude(T t, unsigned ulp)
Adds the given number of ULPs (Units in the Last Place) to the given floating-point number.
BVH_ALWAYS_INLINE T robust_max(T a, T b)
BVH_ALWAYS_INLINE T atomic_max(std::atomic< T > &atomic, const T &value)
Computes the maximum between an atomic variable and a value, and returns the value previously held by...
BVH_ALWAYS_INLINE T fast_mul_add(T a, T b, T c)
Fast multiply-add operation.
BVH_ALWAYS_INLINE void static_for(F &&f)
Executes the given function once for every integer in the range [Begin, End).
BVH_ALWAYS_INLINE T robust_min(T a, T b)
BVH_ALWAYS_INLINE constexpr T make_bitmask(size_t bits)
Generates a bitmask with the given number of bits.
Helper callable object that just ignores its arguments and returns nothing.
void operator()(Args &&...) const
Helper type that gives an unsigned integer type with the given number of bits.