2 ms·
Here’s a cool video that shows how compilers optimize exponentiation[1]. It seems like a really simple problem on the surface (x^3? Just do xxx), but lots of s
by KMnO4 5y ago
Here’s a cool video that shows how compilers optimize exponentiation[1].
It seems like a really simple problem on the surface (x^3? Just do xxx), but lots of smart people have thought hard about the best way to do it for any arbitrary exponent.
For example, x^15 only needs 5 multiplication instructions.
[1]: https://youtu.be/BfNlzdFa_a4 https://youtu.be/BfNlzdFa_a4