The Decimals of PI for the HP-41
Overview
-You place a positive integer n < 319 in X-register, and your HP-41
returns 5n decimals of PI
Formula:
PI = 2 + (1/3) ( 2 + (1/5) ( 2 + (3/7) ( 2 + ......
( 2 + k/(k+1) ) .... ) ) )
Program Listing
Data Registers:
R00 = n R01 ................... Rnn = the
decimals of PI by groups of 5 digits.
Flags: /
Subroutines: /
01 LBL "PI"
02 CLRG 03 STO 00 04 5 05 * 06 2 07 LOG 08 / 09 INT 10 STO N 11 2 12 RCL 00 13 E3 14 / 15 + 16 STO M |
17 E5
18 STO O 19 ISG N 20 LBL 01 21 RCL M 22 RCL O 23 ST+ X 24 RCL 01 25 + 26 RCL N 27 * 28 STO 01 29 LASTX 30 ST+ X 31 ENTER 32 SIGN |
33 +
34 STO P 35 MOD 36 ST- 01 37 LASTX 38 ST/ 01 39 CLX 40 RCL O 41 * 42 LBL 02 43 RCL IND Y 44 RCL N 45 * 46 + 47 RCL X 48 RCL P |
49 MOD
50 ST- Y 51 X<>Y 52 LASTX 53 / 54 RCL O 55 ST* Z 56 X>Y? 57 GTO 03 58 ST- Y 59 SIGN 60 ST- T 61 ST+ IND T 62 ST+ T 63 LBL 03 64 RDN |
65 STO IND Z
66 RDN 67 ISG Y 68 GTO 02 69 DSE N 70 GTO 01 71 E5 72 ST+ 01 73 ST+ 01 74 ST/ 01 75 RCL 00 76 .1 77 % 78 ISG X 79 CLA 80 END |
( 125 bytes / SIZE nnn+1
)
STACK | INPUT | OUTPUT |
X | n < 319 | 1.nnn |
Example1: Calculate 5 x 8 = 40
decimals of PI
8 XEQ "PI" >>> 1.008 ---Execution time = 11m14s---
-And we find in registers R01 thru R08: ( add zeros on the left if need be )
3.14159 26535 89793 23846 26433 83279 50288 41971
-All these decimals are exact !
Example2: Calculate 5 x 318 = 1590 decimals of PI
SIZE 319
318 XEQ "PI" >>>> 1.318 ---Execution time = 27m20s--- With V41 in Turbo Mode
-And we get in registers R01 thru R318: ( add zeros on the
left if need be )
3.14159 26535 89793 23846 26433 83279
50288 41971 69399 37510 58209 74944
59230 78164 06286 20899 86280 34825
34211
70679 82148 08651 32823 06647
09384 46095 50582 23172 53594 08128
48111 74502 84102 70193 85211 05559
64462 29489
54930 38196 44288 10975 66593
34461 28475 64823 37867 83165 27120
19091 45648 56692 34603 48610 45432
66482 13393
60726 02491 41273 72458 70066
06315 58817 48815 20920 96282 92540
91715 36436 78925 90360 01133 05305
48820 46652
13841 46951 94151 16094 33057
27036 57595 91953 09218 61173 81932
61179 31051 18548 07446 23799 62749
56735 18857
52724 89122 79381 83011 94912
98336 73362 44065 66430 86021 39494
63952 24737 19070 21798 60943 70277
05392 17176
29317 67523 84674 81846 76694
05132 00056 81271 45263 56082 77857
71342 75778 96091 73637 17872 14684
40901 22495
34301 46549 58537 10507 92279
68925 89235 42019 95611 21290 21960
86403 44181 59813 62977 47713 09960
51870 72113
49999 99837 29780 49951 05973
17328 16096 31859 50244 59455 34690
83026 42522 30825 33446 85035 26193
11881 71010
00313 78387 52886 58753 32083
81420 61717 76691 47303 59825 34904
28755 46873 11595 62863 88235 37875
93751 95778
18577 80532 17122 68066 13001
92787 66111 95909 21642 01989 38095
25720 10654 85863 27886 59361 53381
82796 82303
01952 03530 18529 68995 77362
25994 13891 24972 17752 83479 13151
55748 57242 45415 06959 50829 53311
68617 27855
88907 50983 81754 63746 49393
19255 06040 09277 01671 13900 98488
24012 85836 16035 63707 66010 47101
81942 95559
61989 46767 83744 94482 55379
77472 68471 04047 53464 62080 46684
25906 94912 93313 67702 89891 52104
75216 20569
66024 05803 81501 93511 25338
24300 35587 64024 74964 73263 91419
92726 04269 92279 67823 54781 63600
93417 21641
21992 45863 15030 28618 29745
55706 74983 85054 94588 58692 69956
90927 21079 75093 02955 32116 53449
87202 75596
02364 80665 49911 98818 34797
75356 63698 07426 54252 78625 51818
41757 46728 90977
-Here again, all the decimalss are correct.
Notes:
-Synthetic register P is used, so don't interrupt "PI"
-The last decimal is sometimes doubtful.
-This is obviously not a fast program.
-In example2 - without a good emulator - execution time could reach
more than 11 days !