1 #ifndef MF_UTILITY_MISC_H_
2 #define MF_UTILITY_MISC_H_
13 template<
typename Numeric>
14 Numeric
sq(Numeric n) {
return n * n; }
23 T
clamp(T value, T minimum, T maximum);
32 return (x != 0) && !(x & (x - 1));
38 return (x % base == 0);
49 bool is_odd(T x) {
return (x % 2) != 0; }
53 bool is_even(T x) {
return (x % 2) == 0; }
bool is_odd(T x)
Check if x is odd.
Definition: misc.h:49
bool is_power_of_two(T x)
Check if x is a power of 2.
Definition: misc.h:31
bool is_multiple_of(T x, T base)
Check if x is a multiple of base, including zero.
Definition: misc.h:37
bool is_even(T x)
Check if x is even.
Definition: misc.h:53
bool file_exists(const std::string &filepath)
Check if a file at filename exists.
Definition: misc.cc:8
T clamp(T value, T minimum, T maximum)
Clamp value between minimum and maximum value.
Definition: misc.tcc:17
Numeric sq(Numeric n)
Compute square of a number.
Definition: misc.h:14
T gcd(T a, T b)
Compute greatest common divisor of a and b.
Definition: misc.tcc:25
T * advance_raw_ptr(T *ptr, std::ptrdiff_t diff) noexcept
Advance a pointer ptr of any type by diff bytes.
Definition: misc.tcc:9
bool is_nonzero_multiple_of(T x, T base)
Check if x is a non-zero multiple of base.
Definition: misc.h:43