9#include "type_traits.hpp"
19#if TT_COMPILER == TT_CC_MSVC
22#if TT_PROCESSOR == TT_CPU_X64
28constexpr long long pow10_table[20] {
43 100'000'000'000'000LL,
44 1'000'000'000'000'000LL,
45 10'000'000'000'000'000LL,
46 100'000'000'000'000'000LL,
47 1'000'000'000'000'000'000LL,
50constexpr long long pow10ll(
int x)
noexcept {
51 tt_axiom(x >= 0 && x <= 18);
52 return pow10_table[x];
58template<
typename T, std::enable_if_t<std::is_
integral_v<T> && std::is_
unsigned_v<T>,
int> = 0>
59constexpr int bsr(T x)
noexcept
61 return static_cast<int>(
sizeof(T) * 8 - std::countr_zero(x)) - 1;
67constexpr T make_mask(T x)
69 ttlet x_ =
static_cast<unsigned long long>(x) + 1;
70 ttlet p2 = std::bit_ceil(x_);
71 return static_cast<T
>(p2 - 1);
76constexpr T median(T a, T b, T c)
noexcept {
80inline bool almost_equal(
float a,
float b)
noexcept {
87 auto a__ =
static_cast<int>(a_ & 0x7ffffff);
88 auto b__ =
static_cast<int>(b_ & 0x7ffffff);
90 if ((a_ < 0) == (b_ < 0)) {
91 return std::abs(a__ - b__) < 10;
93 return std::abs(a__ + b__) < 10;
97template<
typename Iterator>
98auto mean(Iterator first, Iterator last)
102 ttlet sum = std::reduce(first, last, init);
108template<
typename Iterator,
typename T>
109auto stddev(Iterator first, Iterator last, T mean)
113 ttlet sum =
std::accumulate(first, last, init, [=](ttlet &acc, ttlet &value) {
114 ttlet tmp = value - mean;
115 return acc + tmp*tmp;