Post Reply 
Natural logarithm of 2 [HP-15C/HP-42S/Free42 & others]
11-14-2019, 12:04 AM
Post: #21
RE: Natural logarithm of 2 [HP-15C/HP-42S/Free42 & others]
(11-11-2019 06:14 PM)Gerson W. Barbosa Wrote:  n = 1663 will be enough for 1000 digits:

It may be better to make n even, avoiding 1 square root:

\(\Large \frac{\pi}{\log 2}\normalsize ≈ AGM(2n, \frac{2n}{2^{n-2}}) = AGM(n + \frac{n}{2^{n-2}}, \frac{2n}{2^{n/2-1}}) \)

With n=1662, loop count down to 17.

Code:
OPTION ARITHMETIC DECIMAL_HIGH
LET n = 1662
LET nd = 1000
PRINT "Log(2) = "
LET t = TIME 
LET c = 2^(n/2-1)
LET a = n + n/(c*c)
LET b = (n+n)/c
FOR i = 1 TO 17
   LET c = a
   LET a = (a + b)/2
   LET b = SQR(b*c)
NEXT i
LET c = (a + b)/2
LET a = c - (a-b)^2/(16*c)
LET g = PI/a
LET r = TIME - t
LET r$ = STR$(g)                           
PRINT
PRINT "0";
PRINT r$(0:1);
FOR i = 2 TO nd + 1
   PRINT r$(i:i);
   IF MOD((i - 1),10) = 0 THEN PRINT " ";
   IF MOD((i - 1),50) = 0 THEN 
      PRINT
      PRINT "  ";
   END IF
NEXT i
IF MOD (i - 2,50) <> 0  OR nd = 0 THEN PRINT
PRINT 
PRINT "Runtime: ";
PRINT  USING "0.##": r;
PRINT " seconds"
END
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Natural logarithm of 2 [HP-15C/HP-42S/Free42 & others] - Albert Chan - 11-14-2019 12:04 AM



User(s) browsing this thread: 1 Guest(s)