0

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!

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

1 Answer 1

0

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.