Skip to content

Commit

Permalink
Optimize exponentiation of base 2
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Jun 16, 2020
1 parent 0c59fcd commit 216466d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/intx/intx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,9 @@ template <unsigned N>
constexpr uint<N> exp(uint<N> base, uint<N> exponent) noexcept
{
auto result = uint<N>{1};
if (base == 2)
return result << exponent;

while (exponent != 0)
{
if ((exponent & 1) != 0)
Expand Down

0 comments on commit 216466d

Please sign in to comment.