Post Reply 
[VA] SRC#002- Almost integers and other beasties
02-10-2019, 12:48 PM (This post was last modified: 02-10-2019 12:56 PM by Gerson W. Barbosa.)
Post: #26
RE: [VA] SRC#002- Almost integers and other beasties
(02-10-2019 02:41 AM)Gerson W. Barbosa Wrote:  %%HP: T(3)A(R)F(.);
\<< 126 40 'DIGITS' STO 0 1 ROT
  FOR k 1 FNEG k FY\|^X k FDIV 2 k FY\|^X 1 FSUB FDIV FADD
  NEXT DUP FADD 2 FLN FDIV 1 12 FDIV FADD FPI FSQ 6 FDIV 2 FLN FSQ FDIV FADD ZZ\<-\->F DROP \->STR DUP HEAD "." + SWAP TAIL +
\>>

EVAL ->

"1.000000000001237412575736110228719610648"

The RPL program above requires the LongFloat library.

Number of iterations = Ceil(W(10^n*ln(2))/ln(2)), where n = number of digits and W(x) is the Lambert W function.

This is a more generic version that takes the desired number of digits, n, as an argument. As I am using an approximation for W(x), the estimation of the required number of iterations might not be exact for small values of n. Both programs are basically a straightforward conversion of Valentin's HP-71B program in post #21.

100

%%HP: T(3)A(R)F(.);
\<< RCLF SWAP -105 CF -3 CF DUP 'DIGITS' STO ALOG 2 LN * LN DUP LN - LASTARG SWAP / + 2 LN / CEIL 0 1 ROT
  FOR k 1 FNEG k FY\|^X k FDIV 2 k FY\|^X 1 FSUB FDIV FADD
  NEXT DUP FADD 2 FLN FDIV 12 FINV FADD FPI FSQ 6 FDIV 2 FLN FSQ FDIV FADD ZZ\<-\->F NEG SWAP \->STR DUP SIZE ROT \=/ -51 FC? { "." } { "," } IFTE UNROT { DUP TAIL SWAP HEAD } { "0" } IFTE UNROT + + SWAP STOF
\>>

EVAL ->

1.000000000001237412575736110228719610646672874297732048196548443844171825640530​428850913885586193525
(132.59 seconds on the HP 50g)

 5 -> 0.99990

 6 -> 1.00000

 7 -> 1.000000

12 -> 1.00000000001

20 -> 1.0000000000012374126

40 -> 1.000000000001237412575736110228719610648

50 -> 1.0000000000012374125757361102287196106466728742977
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC#002- Almost integers and other beasties - Gerson W. Barbosa - 02-10-2019 12:48 PM



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