Pi Approximation Day - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: Pi Approximation Day (/thread-15364.html) Pi Approximation Day - Gerson W. Barbosa - 07-22-2020 11:22 PM Today is Pi Approximation Day. To celebrate it, here is an HP 50g program based on a variation of the Wallis Product. Here we use (2/1*4/3*6/5*8/7*...) plus a correction factor in continued fraction form. The number of digits per iteration is slightly less than 21/10, which is being used by the program, so this has to be adjusted. The argument of the RPL program is the desired number of decimal places. For n = 100, the program returns 98 correct decimal digits; for n = 200, the program gets all of them right. This takes about one minute on the emulator because of the slowness of EXPAND to process long algebraic expressions. Code: ``` « PUSH RAD -105 CF -3 CF DUP 10 * 21 / CEIL 0 2 ROT 8 OVER * PICK3 + UNROT 1   FOR i i DUP + DUP 1 - UNROT * OVER / SWAP SQ 4 ROLL 4 PICK + / UNROT -1   STEP SQ UNROT 2 / + / EXPAND FXND DUP SIZE R→I ALOG OVER - PICK3 * SWAP IQUOT  + →STR DUP HEAD 0 I→R →STR TAIL + SWAP TAIL + 1 ROT 2 + SUB POP »``` 253 bytes, CKS = # 537h 3,141592653589793238462643383279502884197169399375105820974944592307816406286208​99862803482534211706798214808651328230664709384460955058223172535940812848111745​ 028410270193852110555964462294895493038196 HP-75C program: Code: ``` 10 INPUT N 15 C=0 20 D=8*N+2 25 W=2 30 FOR I=N TO 1 STEP -1 35 T=2*I-1 40 W=W*(T+1)/T 45 C=T*T/(C+D) 50 NEXT I 55 C=C+D/2 60 DISP W*W/C```