diff options
author | Anthony Wang | 2021-04-29 20:40:27 +0000 |
---|---|---|
committer | GitHub | 2021-04-29 20:40:27 +0000 |
commit | ed81135660700743dc43cc8c649f368639eb41ef (patch) | |
tree | bbb5bbc1eac081724f2f4def180b05bf9fef6320 /fast-pow | |
parent | 2afb3344846a3d419dff293bb518e2f1a88b6f1b (diff) |
A very scary for loop
Diffstat (limited to 'fast-pow')
-rw-r--r-- | fast-pow/pow.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/fast-pow/pow.cpp b/fast-pow/pow.cpp new file mode 100644 index 0000000..76c6702 --- /dev/null +++ b/fast-pow/pow.cpp @@ -0,0 +1,9 @@ +#include <iostream> +#include <numbers> + +auto pw(auto b,int e){auto r=b;for(--e<<=1;e>>=1;r*=(e&1)*b,b*=b);return r;} + +int main() { + std::cout << pw(2, 4) << std::endl; + std::cout << pw(std::numbers::e, 2) << std::endl; +} |