Skip to content

Commit

Permalink
Merge pull request #146 from chfast/exp
Browse files Browse the repository at this point in the history
Optimize exponentiation of base 2
  • Loading branch information
chfast authored Jun 16, 2020
2 parents 0c59fcd + 216466d commit 54aebb3
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 54aebb3

Please sign in to comment.