How to estimate the number of decimals places needed for exponentiation?

47 Views Asked by At

I'm working on an application that requires arbitrary precision calculations. There is no power function for computing a number to the power of another. However, there are functions for computing exp(x), mul(x, y) and ln(x), so I'm using the identity x ^ y = exp(y * ln(x)) to compute exponentiation. The functions allow me specifying the number of decimals (scale) as the precision. For example: ln(x, 10) will return a result precise up to the 10th decimal place.

The question is: how to compute the number of decimals places needed for computing the exponentiation precise up to a given scale? In other words, given the function pow(x, y, s), where x is the base, y the exponent and s the scale (number of decimal places), what should be the value of s1 in such way that the result will be exact up to the sth decimal place?

pow(x, y, s) => exp(mul(y, ln(x, s1), s1), s1)