Re: Check on mathematical identity Message #11 Posted by Paul Dale on 24 Aug 2012, 7:38 p.m., in response to message #7 by Namir
The comment before the natural logarithm function from the 34S source code is:
/* Natural logarithm.
*
* Take advantage of the fact that we store our numbers in the form: m * 10^e
* so log(m * 10^e) = log(m) + e * log(10)
* do this so that m is always in the range 0.1 <= m < 2. However if the number
* is already in the range 0.5 .. 1.5, this step is skipped.
*
* Then use the fact that ln(x^2) = 2 * ln(x) to range reduce the mantissa
* into 1/sqrt(2) <= m < 2.
*
* Finally, apply the series expansion:
* ln(x) = 2(a+a^3/3+a^5/5+...) where a=(x1)/(x+1)
* which converges quickly for an argument near unity.
*/
I don't remember making any any other refinements but might have. This is around line 750 of decn.c if you want to look at the actual code.
The native decNumber library uses Newton's method after an initial estimate and this proved very slow. I then switched to the AGM code which was faster but quite a bit less accurate. I later moved to the current code which is both faster again and accurate. Even so, our code for the natural logarithm is on the slow side and a faster method would be appreciated. Unfortunately, I can't justify the use of tables of piecewise polynomial or rational approximations which seem to be the typical way to implement this function.
 Pauli
