From ed81135660700743dc43cc8c649f368639eb41ef Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 29 Apr 2021 20:40:27 +0000 Subject: A very scary for loop --- fast-pow/pow.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 fast-pow/pow.cpp 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 +#include + +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; +} -- cgit v1.2.3-70-g09d2