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 {
84constexpr bool almost_equal(
float a,
float b)
noexcept {
85 constexpr int32_t epsilon = 5;
87 ttlet a_ = std::bit_cast<int32_t>(a);
88 ttlet b_ = std::bit_cast<int32_t>(b);
91 ttlet a_abs =
static_cast<int64_t
>(a_ & 0x7ffffff);
92 ttlet b_abs =
static_cast<int64_t
>(b_ & 0x7ffffff);
96 ttlet delta = (a_ < 0) == (b_ < 0) ? a_abs - b_abs : a_abs + b_abs;
99 return delta < epsilon && delta > -epsilon;
102template<
typename Iterator>
103auto mean(Iterator first, Iterator last)
107 ttlet sum = std::reduce(first, last, init);
113template<
typename Iterator,
typename T>
114auto stddev(Iterator first, Iterator last, T mean)
118 ttlet sum =
std::accumulate(first, last, init, [=](ttlet &acc, ttlet &value) {
119 ttlet tmp = value - mean;
120 return acc + tmp*tmp;