26#if HI_COMPILER == HI_CC_MSVC
29#if HI_PROCESSOR == HI_CPU_X64
33namespace hi::inline
v1 {
36template<
typename Iterator>
37[[nodiscard]]
auto mean(Iterator first, Iterator last)
41 hilet sum = std::reduce(first, last, init);
47template<
typename Iterator,
typename T>
48[[nodiscard]]
auto stddev(Iterator first, Iterator last, T mean)
53 hilet tmp = value - mean;
54 return acc + tmp * tmp;
62constexpr bool inplace_max(T& a, T
const& b)
noexcept
70constexpr bool inplace_min(T& a, T
const& b)
noexcept
78constexpr void inplace_clamp(T& a, T
const& lo, T
const&
hi)
noexcept
87[[nodiscard]]
constexpr T abs(T a)
noexcept
89 return a < T{} ? -a : a;
92template<std::
floating_po
int T>
93[[nodiscard]]
constexpr bool almost_equal(T a, T b)
noexcept
96 return std::abs(a - b) <= e;
104template<std::
floating_po
int T>
107 return degree * (std::numbers::pi_v<T> / T{180.0});
115template<std::
unsigned_
integral T>
116[[nodiscard]]
constexpr T floor(T value, T
alignment)
noexcept
126template<std::
unsigned_
integral T>
127[[nodiscard]]
constexpr T ceil(T value, T
alignment)
noexcept
132template<std::
floating_po
int T>
133[[nodiscard]]
constexpr bool isnan(T value)
noexcept
135 return not (value == value);
138constexpr unsigned long long pow10_table[20] = {
151 1'000'000'000'000ULL,
152 10'000'000'000'000ULL,
153 100'000'000'000'000ULL,
154 1'000'000'000'000'000ULL,
155 10'000'000'000'000'000ULL,
156 100'000'000'000'000'000ULL,
157 1'000'000'000'000'000'000ULL,
160[[nodiscard]]
constexpr uint64_t pow10(
unsigned int x)
noexcept
163 return pow10_table[x];
166template<std::
unsigned_
integral T>
167[[nodiscard]]
constexpr unsigned int decimal_width(T x)
170 constexpr uint8_t guess_table[] = {
171 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4,
172 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9,
173 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14,
174 14, 14, 15, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 18
178 hilet num_bits = std::bit_width(x);
180 hilet guess = guess_table[num_bits];
181 return guess + wide_cast<unsigned int>(x >= pow10(guess));
184template<std::
signed_
integral T>
185[[nodiscard]]
constexpr unsigned int decimal_width(T x)
187 return decimal_width(narrow_cast<std::make_unsigned_t<T>>(abs(x)));
Utilities to assert and bound check.
#define hi_axiom_bounds(x,...)
Specify an axiom that the value is within bounds.
Definition assert.hpp:264
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
Utilities used by the HikoGUI library itself.
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
Functions for casting values between types savely.
DOXYGEN BUG.
Definition algorithm.hpp:13
constexpr T to_radian(T degree) noexcept
Convert degree to radian.
Definition math.hpp:105
geometry/margins.hpp
Definition cache.hpp:11
Horizontal/Vertical alignment combination.
Definition alignment.hpp:238