3 ms·
IMHO it's a bit cheeky to use exp2 from the standard library. It's likely got all the same math exp does. Fortunately, if you know that your exponent is an inte
by nwallin 6y ago
IMHO it's a bit cheeky to use exp2 from the standard library. It's likely got all the same math exp does. Fortunately, if you know that your exponent is an integer, there's a constant time version. It's 5 instructions: add, and, shift, mov, ret.
https://godbolt.org/z/KNyoVd https://godbolt.org/z/KNyoVd
- fractionalhare 6y agoExcellent, thank you! I agree, I had the use of `exp2(x)` on my list of implementation nits to revisit. I'm going to revise to use your method and credit the comment.
- _0ffh 6y agoI think you can spare the "and", because if you overflow the exponent field, the result will be wrong either way.