diff --git a/include/boost/multiprecision/detail/functions/pow.hpp b/include/boost/multiprecision/detail/functions/pow.hpp index b7ab2933d..4338650b1 100644 --- a/include/boost/multiprecision/detail/functions/pow.hpp +++ b/include/boost/multiprecision/detail/functions/pow.hpp @@ -43,6 +43,27 @@ inline void pow_imp(T& result, const T& t, const U& p, const std::integral_const return; } + switch (p) + { + case 0: + result = int_type(1); + return; + case 1: + result = t; + return; + case 2: + eval_multiply(result, t, t); + return; + case 3: + eval_multiply(result, t, t); + eval_multiply(result, t); + return; + case 4: + eval_multiply(result, t, t); + eval_multiply(result, result); + return; + } + // This will store the result. if (U(p % U(2)) != U(0)) {