aboutsummaryrefslogtreecommitdiff
path: root/fast-pow/pow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fast-pow/pow.cpp')
-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;
+}