What's an efficient way to do exponentials of numbers with decimals, such as when compounding interest rate calculations?

For example: 1.001 ** 69

As of now, I naively implement it like this:

uint mantissa = 1e3;
uint rate = 1;
uint periods = 69;
uint out = mantissa;
for(uint i=0; i < periods; i++){
  out = out * (mantissa + rate);
  out = out / mantissa;

My worry is if the number of periods get big then I'm running a pretty inefficient loop. Anyone have any better ideas? Are there any libraries that do this implementation for me? Thanks!

  • Can your number of period vary or is it constant ?
    – hroussille
    Nov 30, 2021 at 7:39

1 Answer 1


Just do not store the accumulated interest on the main account, but store them separately.

Or use a simplified formula for small percentages: (1+x)^y = 1+x*y.

For values x=0.001 and y=100, the true value will be 1.105, and the simplified 1.100

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.