Natural logarithm  ln(2)

It is not very old, as its concept was introduced by Saint-Vincent and de Sarasa before 1649!

ln(2) = 0.69314718055994530941723212145817656807550013436025...

The alternating sum   1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + 1/7 - 1/8+ ...
The first few decimals of this pervasive constant are worth memorizing!


...by shortening the labors, doubled the life of the astronomer.
- Pierre Simon de Laplace (1749-1827) about logarithms.


You have no idea, how much poetry there is in the calculation of a table of logarithms!
- Karl Friedrich Gauss (1777-1855), to his students.


The two following programs are short C program from Pascal Sebah (Jan 2000) to compute 2400 decimal places of log(2). In the two algorithms, the number of digits is given by log10(a).n where a is the working base (here a = 103 or less if you want to compute more digits) and c is the numbers of iteration required, the size of the array f[] is c+1.

The first program is based on the hypergeometric representation of x-1log(1-x) with x = 1/2 (see [1]) :
                            main() {
                                int a=1000,b=0,c=7973,d,f[7974],n=800,k;
                                for(;b<c;f[b++]=5);
                                for(;n--;d+=*f*a,printf("%.3d",d/a),*f=d%a)
                                for(d=0,k=c;--k;d/=b,d*=k)f[k]=(d+=f[k]*a)%(b=2*k+2);
                            }
                            

The second program is almost the same but deduced from an alternating series of log(2) given in the essay on this number, it's about three time faster than the previous one :
                            main() {
                                int a=1000,b=0,c=2658,d=75,f[2659],n=800,k;
                                for(;b<c;f[b++]=d,d=-d);
                                for(;n--;d+=*f*a,printf("%.3d",d/a),*f=d%a)
                                for(d=0,k=c;--k;d/=b,d*=k)f[k]=(d+=f[k]*a)%(b=8*k+4);
                            }
                            

[1] M. Abramowitz and I. Stegun, Handbook of Mathematical Functions, Dover, New York, (1964)


Powered By   Kotisivut.com - Luotettava webhotelli    CodeIgniter PHP Framework   BaseURL: https://datatuki.net/web/  Page rendered in 0.3886 seconds