Skip to content

Instantly share code, notes, and snippets.

@neacsum
Created December 1, 2021 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neacsum/7fec051280b5770b4dbacb8a8a11320e to your computer and use it in GitHub Desktop.
Save neacsum/7fec051280b5770b4dbacb8a8a11320e to your computer and use it in GitHub Desktop.
Integer exponentiation template function
#pragma once
/*
Integer exponentiation function.
In most cases, it is faster than standard pow function
*/
template <typename T>
T ipow (T base, int exp)
{
T result = 1;
while (exp)
{
if (exp & 1)
result *= base;
exp >>= 1;
base *= base;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment