From 216466d1443020053b88942080c9fe6128e09ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 15 Jun 2020 12:40:59 +0200 Subject: [PATCH] Optimize exponentiation of base 2 --- include/intx/intx.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/intx/intx.hpp b/include/intx/intx.hpp index bd3b8455..7886d639 100644 --- a/include/intx/intx.hpp +++ b/include/intx/intx.hpp @@ -593,6 +593,9 @@ template constexpr uint exp(uint base, uint exponent) noexcept { auto result = uint{1}; + if (base == 2) + return result << exponent; + while (exponent != 0) { if ((exponent & 1) != 0)