13#ifndef UTILITIES_POWER_HH
14#define UTILITIES_POWER_HH
31 constexpr R
power(R base,
int exp)
33 if (exp>1 && exp%2==0)
35 R p =
power(base,exp/2);
39 return base *
power(base,exp-1);
41 return static_cast<R
>(1)/
power(base,-exp);
43 return static_cast<R
>(1);
68 for (
int i=2; i<=n; ++i)
78 namespace PowerDetails
81 constexpr int sqrti(
int lo,
int mid,
int hi,
int n)
84 : n / mid < mid ? sqrti(lo,(lo+mid)/2,mid-1,n)
85 : sqrti(mid,(mid+hi+1)/2,hi,n);
98 return PowerDetails::sqrti(0,(n+1)/2,n,n);
constexpr R power(R base, int exp)
Computes integral powers of values in a multiplicative half-group.
constexpr int sqrti(int n)
Computes floor(sqrt(n)) for integers n at compile time.
constexpr R square(R x)
returns the square of its argument.
constexpr R faculty(int n)
Computes faculties. Is this somewhere in the standard? no.