aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2021-04-29 20:40:27 +0000
committerGitHub2021-04-29 20:40:27 +0000
commited81135660700743dc43cc8c649f368639eb41ef (patch)
treebbb5bbc1eac081724f2f4def180b05bf9fef6320
parent2afb3344846a3d419dff293bb518e2f1a88b6f1b (diff)
A very scary for loop
-rw-r--r--fast-pow/pow.cpp9
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;
+}