I came across an interesting quirk in Python when I tried running some floating-point arithmetic and got two different results when I used successive multiplication vs. exponentiation.
Here's the code snippet
money = 1000.0
interest_rate = 1.15
# Exponentiation
after_five_years = (money * (interest_rate ** 5)) - 500
print(after_five_years)
1511.3571874999993
# Successive multiplication
print((((((money * interest_rate) * interest_rate) * interest_rate) * interest_rate) * interest_rate) - 500)
1511.3571874999996
As you can see, the final decimal place is different between the two computations. I am guessing it has something to do with floating-point arithmetic and precision loss. My hypothesis is that the successive multiplication operation results in a lower precision than exponentiation. However, I wasn't sure how I could go about confirming this hypothesis.