18namespace shamunits::details {
21 template<
int power,
class T>
24 if constexpr (power < 0) {
26 }
else if constexpr (power == 0) {
28 }
else if constexpr (power % 2 == 0) {
31 }
else if constexpr (power % 2 == 1) {
45 inline constexpr T
ipow(T a,
int n, T a_inv)
noexcept {
46 T base = (n < 0) ? a_inv : a;
47 unsigned k = (n < 0) ? 0u -
static_cast<unsigned>(n) :
static_cast<unsigned>(n);
50 for (
unsigned t = k; t != 0; t >>= 1) {
55 for (
int b = top_bit; b >= 0; --b) {
57 if (((k >> b) & 1u) != 0) {
constexpr T pow_constexpr_fast_inv(T a, T a_inv) noexcept
Constexpr power expansion function with supplied inverse for negative values.
constexpr T ipow(T a, int n, T a_inv) noexcept
Runtime twin of pow_constexpr_fast_inv, for an exponent only known at run time.