shopspring / decimal

Arbitrary-precision fixed-point decimal numbers in Go
Other
6.41k stars 623 forks source link

Add improved implementation of power operation #358

Closed mwoss closed 7 months ago

mwoss commented 7 months ago

PR adds an improved implementation of the Pow method. It also adds three new methods - PowWithPrecision, PowInt32, and PowBigInt. PowWithPrecision can be used for calculating powers with high, specific precision. PowInt32 and PowBigInt can be used for more performant calculation of decimal powers in case the exponent is simply an integer.

It took me some time to implement them as it was quite a difficult task, especially when we care about correctness and high precision. I also had to implement natural exponent and natural logarithm implementation for that.