13#ifndef UTILITIES_POWER_HH
14#define UTILITIES_POWER_HH
32 if (exp>1 && exp%2==0) {
33 R p =
power(base,exp/2);
37 return base *
power(base,exp-1);
39 return static_cast<R
>(1)/
power(base,-exp);
41 return static_cast<R
>(1);
62 for (
int i=2; i<=n; ++i)
70 namespace PowerDetails
73 constexpr int sqrti(
int lo,
int mid,
int hi,
int n)
76 : n / mid < mid ?
sqrti(lo,(lo+mid)/2,mid-1,n)
77 :
sqrti(mid,(mid+hi+1)/2,hi,n);
R faculty(int n)
Computes faculties. Is this somewhere in the standard? no.
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.
R square(R x)
returns the square of its argument.