Hacker News new | past | comments | ask | show | jobs | submit login

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.


Excellent, 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.

I think you can spare the "and", because if you overflow the exponent field, the result will be wrong either way.

Applications are open for YC Winter 2022

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact