560 digits of Pi
calculated on the HP-41

 

                   

 

 

 

 

Armed with only your HP-41,
will you be able to find
the error in the painting?

 

 

 

 

 

 

 

 

« Une erreur dans les 1000 décimales de Pi »

Original painting from Anne Garnier, 2003

 

 

 

 

 

 

Calculating multiple digits of Pi with a computer was one of my first programs.

 

The program below is an implementation for the HP-41, just for the challenge to port it on my favorite pocket calculator of the time.

 

I got 560 digits of Pi with my HP-41CV.

 

 01*LBL "CALPI"        53 STO 12            105 RCL 02            157 STO IND 07        209 STO IND 07        261 DSE 07           

 02 CLRG               54*LBL 11            106 FRC               158 RCL 08            210 RCL 06            262 GTO 07           

 03 6                  55 XEQ 26            107 RCL 11            159 *                 211 DSE 07            263 RTN              

 04 +                  56 XEQ 27            108 *                 160 -                 212 GTO 05            264*LBL 31           

 05 7                  57 XEQ 29            109 1                 161 ISG 07            213 RTN               265 RCL 00           

 06 /                  58 2                 110 +                 162 GTO 01            214*LBL 29            266 STO 07           

 07 INT                59 ST+ 12            111 RCL 02            163 RTN               215 RCL 02            267 1                 

 08 STO 10             60 XEQ 26            112 INT               164*LBL 27            216 STO 07            268*LBL 08           

 09 16                 61 XEQ 27            113 RCL 11            165 RCL 01            217 1                 269 RCL 04           

 10 STO 00             62 XEQ 28            114 /                 166 STO 07            218*LBL 06            270 *                

 11 +                  63 RCL 13            115 +                 167 0                 219 RCL IND 07        271 STO Y            

 12 STO 01             64 RCL 12            116 STO 07            168*LBL 04            220 +                 272 RCL 09           

 13 1                  65 2                 117 FIX 0             169 RCL 04            221 RCL 07            273 /                

 14 -                  66 +                 118 SF 29             170 *                 222 RCL 10            274 INT              

 15 1 E3               67 STO 12            119 SF 21             171 RCL 07            223 -                 275 STO IND 07       

 16 STO 11             68 X<=Y?             120 "PI="             172 RCL 10            224 X<>Y              276 RCL 09           

 17 /                  69 GTO 11            121 ARCL 06           173 -                 225 RCL IND Y         277 *                

 18 ST+ 00             70 4                 122 AVIEW             174 X<>Y              226 -                 278 -                

 19 RCL 01             71 STO 08            123 CF 29             175 RCL IND Y         227 RCL 05            279 ISG 07           

 20 RCL 10             72 XEQ 30            124*LBL 14            176 +                 228 +                 280 GTO 08           

 21 +                  73 239               125 VIEW IND 07       177 STO Y             229 STO Y             281 RTN              

 22 1                  74 STO 09            126 ISG 07            178 RCL 12            230 RCL 04            282*LBL 32           

 23 -                  75 XEQ 31            127 GTO 14            179 /                 231 /                 283 RCL 02           

 24 RCL 11             76 XEQ 32            128 CLX               180 INT               232 INT               284 STO 07           

 25 /                  77 RCL 09            129 RTN               181 STO IND 07        233 STO 06            285 1                

 26 STO 02             78 STO 08            130*LBL 20            182 RCL 12            234 RCL 04            286*LBL 09           

 27 ST+ 01             79 XEQ 20            131 RCL 10            183 *                 235 *                 287 RCL IND 07       

 28 RCL 11             80 3                 132 7                 184 -                 236 -                 288 +                

 29 *                  81 STO 12            133 *                 185 ISG 07            237 STO IND 07        289 RCL 07           

 30 RCL 10             82*LBL 12            134 2                 186 GTO 04            238 RCL 06            290 RCL 10           

 31 +                  83 XEQ 26            135 +                 187 RTN               239 DSE 07            291 ENTER^           

 32 ST+ 02             84 XEQ 26            136 RCL 09            188*LBL 28            240 GTO 06            292 +                

 33 RCL IND 02         85 XEQ 27            137 LOG               189 RCL 02            241 RTN               293 -                

 34 1 E7               86 XEQ 28            138 /                 190 STO 07            242*LBL 30            294 X<>Y              

 35 STO 04             87 2                 139 INT               191 0                 243 RCL 02            295 RCL IND Y        

 36 1                  88 ST+ 12            140 1                 192*LBL 05            244 STO 07            296 -                

 37 -                  89 XEQ 26            141 +                 193 RCL IND 07        245 0                 297 RCL 05           

 38 STO 05             90 XEQ 26            142 STO 13            194 +                 246*LBL 07            298 +                

 39 RCL 04             91 XEQ 27            143 RTN               195 RCL 07            247 RCL IND 07        299 STO Y            

 40 5                  92 XEQ 29            144*LBL 26            196 RCL 10            248 RCL 08            300 RCL 04           

 41 STO 09             93 RCL 13            145 RCL 00            197 -                 249 *                 301 /                

 42 /                  94 RCL 12            146 STO 07            198 X<>Y              250 +                 302 INT              

 43 STO IND 00         95 2                 147 0                 199 RCL IND Y         251 STO Y             303 STO 06           

 44 RCL 01             96 +                 148*LBL 01            200 +                 252 RCL 04            304 RCL 04           

 45 RCL 10             97 STO 12            149 RCL 04            201 STO Y             253 /                 305 *                

 46 +                  98 X<=Y?             150 *                 202 RCL 04            254 INT               306 -                

 47 X<>Y               99 GTO 12            151 RCL IND 07        203 /                 255 STO 06            307 STO IND 07       

 48 STO IND Y         100 4                 152 +                 204 INT               256 RCL 04            308 RCL 06           

 49 25                101 STO 08            153 STO Y             205 STO 06            257 *                 309 DSE 07           

 50 STO 08            102 XEQ 30            154 RCL 08            206 RCL 04            258 -                 310 GTO 09           

 51 XEQ 20            103 BEEP              155 /                 207 *                 259 STO IND 07        311 .END.            

 52 3                 104*LBL 13            156 INT               208 -                 260 RCL 06           

 

Setup: only CALPI in program memory, SIZE 257

Run: 560 XEQ “CALPI”

After CALPI finished to calculate (it took 22h14min for the 560 digits), the results could be printed with:

176.255  STO 02  XEQ “PRTPI”

 

 01*LBL "PRTPI"

 02 "  LES 560 PREM"

 03 "’IERES"

 04 PRA

 05 5

 06 SKPCHR

 07 "DECIMALES DE "

 08 ACA

 09 123

 10 ACCHR

 11 PRBUF

 12 ADV

 13 ACCHR

 14 "=3."

 15 ACA

 16 FIX 0

 17 CF 29

 18 RCL 02

 19 STO 07

 20 1 E6

 21 ENTER^

 22*LBL 01

 23 CLA

 24 CLX

 25 RCL IND 07

 26 X<Y?

 27 "0"

 28 ARCL X

 29 ACA

 30 ISG 07

 31 GTO 01

 32 PRBUF

 33 .END.