I am working on a library for multiple precision floating point numbers. I implemented computation of natural logarithm as follows:
- Factoring of decimal powers first:
$$ln(m*10^e) = \ln(m*10^{(1-n)}) + (e - 1 + n)*\ln(10)$$
here m is mantissa, n is the number of decimal position in m, e is exponent part of a number.
Factoring $m*10^{(1-n)}$ with dividing by 2, so after several divisions it represents a number laying within range [1, 2).
Use series based on inverse hyperbolic tangent https://en.wikipedia.org/wiki/Logarithm#Inverse_hyperbolic_tangent
It does the calculation, but I have two problems:
- it seems to be slow.
- it seems like it lacks precision.
To mitigate the second problem I used increased mantissa, but there is still discrepancy of about 3 least significant decimal digits (I check the results by inverse calculation, i.e $e^{ln(x)}$).
How could I improve this algorithm with regard to above mentioned problems?
lnin postgresql. It uses similar approach, but for step 3 the range is more narrow. So, probably the key is more narrow range, and will try this approach first – stencillogic Jun 12 '22 at 13:55