Computing many digits of Pi


This subject was dealt with the year 2004 by Gene Wright (HP Forum Archives 14). As a newcomer, I only now have noticed the archive. It is said there that there are two programs to compute many digits of pi with the TI-95 calculator, one by Hewlet Ladd (1987) and another by Palmer Hanson (2004). Some members asked then for the Hanson listing, but he answered that was not ready to type the 750 steps by hand, and that he would send an attached copy of the printed listing if the interested people supply him his e-mail address. Well, I would like also to have this listing and that by Hewlet Ladd. Can anyone supply these listings?. In the same archive is a post by Gordon Dyer showing a program to compute pi on a HP-42. However, the program gives only 11 digits. Does anyone know a similar program for the same calculator but computing as many digits as possible? Does anyone know a similar arbitrary precisión program to compute many digits of pi on any calculator (HP or other brands) using only the Machin arctangent formula (pi = 16/arctg (5) - 4/arctg (239))? Many thanks in advance


Katie Wasserman used the formula:

Pi = 20 * arctan(1/7) + 8 * arctan(3/79)

to calculate 96 (correct) digits of pi on a 32SII as described in this article. I would think it would be relatively straight-forward to convert her program to run on the 42S. I've been meaning to convert it to run on the 35s. (That is, thinking “gee, I wonder if Katie’s program could be converted to the 35s, and if so, how many digits could it calculate.”) Katie's program saves 9 digits of pi in each 12-digit register, so with 800 registers, each capable of holding three 12-digit numbers, it should be possible to get 21,600 digits. (Assuming the program would fit with that many data registers allocated. Seems like it ought to, since the original fit in the very limited memory of the 32SII, but I have not really checked to see.)


The program for the 32Sii needs some modification in order to extend it for many more registers. The 9 digits/register was necessary to avoid overflows when just 99 digits are computed. You'll probably need to cut back to 6 digits/register if you're going put this on the 35s and try for 10000+ digits. More to the point, the run time goes up roughly as the square of the number of digits and the 35s isn't much faster than the 32sii so it's going to take.... let's see.....

11 (minutes for around 100 digits) * 9/6 (number of digits per register correction * 100^2 (100 times more digits that go as the square) = ......

pretty close to forever!

The 35s just isn't fast enough to do much useful calculation with all those registers. Even a good (NlogN) sorting routine would likely take longer than anyone would want to wait.



Many thanks Katie

Of course, you are right. Your program is a little wonder, but I know that to compute over a few thousands of digits on any calculator a long job if using classical algorithms linked to trigonometric formulas. I am not sure if the translation to other calculators deserves trying.

Thanks anyway


More to the point, the run time goes up roughly as the square of the number of digits and the 35s isn't much faster than the 32sii so it's going to take.... let's see.....pretty close to forever!

I did not realize this about the technique you implemented on the 32sII. I guess I should have studied it a bit before flippantly postulating about computing 20,000+ digits on the 35s.

(I probably should have realized. After all, if calculating pi was easy, it would not have worked as an effective method to drive a malevolent entity from the computer of the Enterprise. I sure hope that Spock was the only one authorized to instruct the computer to use all resources, to the exlusion of all other processes if I recall correctly, for a particular task.)


There are methods for computing pi that converge quadratically, of course they are also grow linearly with the number of digits required. So, they're ultimate convergence is N*Log(N). I'm not sure if Spock was aware of these methods when he issued his command, but he still would have gotten his intended result -- to be expected from "the best first officer in the fleet" to quote Dr. McCoy.


Many thanks. Katie's program is wonderful given the small amount of memory of the HP-32. I will try to translate it to TI-95. However, it does not use the Machin's formula, but one of the many related ones.


Ola, Juan; ¿que tal?

I'd sugget trying these threads (in addition to Jeff´s):

Yet another not quite pi puzzle

560 Digits of PI in the HP41

Computing PI -- a simple programming problem (Katie's post, mentioned by Jeff)

CALCULATING MANY DIGITS OF PI (This one you have already read, sorry...)

I guess you may find what you need.


Luiz (Brazil)

Edited: 11 Sept 2007, 9:06 a.m.


Muito obrigado, Luiz
I have followed your links. Either i knew them already or these are not useful for my purpose. Thanks again

Juan Pablo


Here's some more interesting forum message links for calculating PI on both the HP-41 and the HP-42:

announcing "deep pi"

Deep PI - On a 42S

Deep Pi on the HP-41cx

Deep Pi - 42S - Some Results

Another Slice of PI

One more slice of PI

Have Fun,



Many thanks, Bill

The links are very useful. I am astonished of the cleverness of the deep.pi program. It would be nice to know used


Hi Juan Pablo!

The following vintage program in french gives 128 digits of PI:

Que j'aime à faire apprendre ce nombre utile aux sages !	3 1 4 1 5 9 2 6 5 3 5
Immortel Archimède, artiste ingénieur, 8 9 7 9
Qui de ton jugement peut priser la valeur ? 3 2 3 8 4 6 2 6
Pour moi, ton problème eut de pareils avantages.4 3 3 8 3 2 7 9
Jadis, mystérieux, un problème bloquait 5 0 2 8 8
Tout l'admirable procédé, l'œuvre grandiose 4 1 9 7 1 6 9
Que Pythagore découvrit aux anciens Grecs. 3 9 9 3 7 5
0 quadrature ! Vieux tourment du philosophe 1 0 5 8 2 9
Insoluble rondeur, trop longtemps vous avez 9 7 4 9 4 4
Défié Pythagore et ses imitateurs. 5 9 2 3 0
Comment intégrer l'espace plan circulaire ? 7 8 1 6 4 0
Former un triangle auquel il équivaudra ? 6 2 8 6 2 0
Nouvelle invention : Archimède inscrira 8 9 9 8
Dedans un hexagone ; appréciera son aire 6 2 8 0 3 4
Fonction du rayon. Pas trop ne s'y tiendra : 8 2 5 3 4 2 1 1 7
Dédoublera chaque élément antérieur ; 0 6 7 9
Toujours de l'orbe calculée approchera ; 8 2 1 4 8 0
Définira limite ; enfin, l'arc, le limiteur 8 6 5 1 3 2 8
De cet inquiétant cercle, ennemi trop rebelle 2 3 0 6 6 4 7
Professeur, enseignez son problème avec zèle 0 9 3 8 4 4

It should run in less one minute on a well trained brain :-))




You are right, Etienne. This is perhaps the fastest algorithm, but it is rather difficult to implement it in a calculator. I knew already the poem by heart, but only the first lines, about 60 digits. There is plenty of similar texts in different languages, helping to memorize even 1000 digits of pi. Of course, there is still a faster algorithm, to look at the many existing printed values, to look in the web for any of the several pi pages, or to use any of the available multiprecision programs, either Derive, Maple, Mathematica, etc. However, none of these ways has much to do with calculators.
Many thanks


I have a pasteup available for my 2004 program for the TI-95. It is a conversion of the TI-59 program by Bob Fruit which appeared in V7N4/5P27 ff of TI PPC Notes. Since you keep your e-mail address private you will have to send your address to me at if you want a copy. I haven't figured out how to attach anything to the secure communication through the museum.

I have not found a pasteup of the Hewlett Ladd program for the TI-95. It is a convwersion of the Science et Vie program for the TI-59 which appeared in V8N3P8-9 of TI PPC Notes. For a translation of the Science et Vie article go to V8N4P21-24 of TI PPC Notes.


It would be nice, If you can send me the TI-95 version too. Thank you.


Many, many thanks! Finally I managed to contact you. I did not realize that my e-mail address was kept private. Here is it: (with the @ sign instead the dots). I would be very grateful if you send me the paste. Besides several HP calculators I still own and use an old TI95. I wonder if your program could be changed to allow the use of either supplementary memory modules up to 32 K or even data recorded in magnetic tape.

Thanks again


I have the 2004 program in an 8K RAM module. I don't think I ever had it on tape since my tape reader isn't working.

I sort of remember having the Hewlett Ladd program on tape but I haven't been able to find it. It is not on a RAM module. I have found a reference in which Hewlett indicated that his program was a translation of a TI-59 program from V8N4P26 of TI PPC Notes, that it was only 296 bytes and would calculate up to 1573 digits.


Using the Spigot Algorithm from Pi Unleashed + HPGCC I can compute 15000 digits of PI in 412 seconds on my 50g. If you are interested I can send you the binary so that you do not need to compile and install the ARM Toolbox. NOTE: Real 50g/49g+ required.

To use:

15000 pidf
Output to stack:
bytes used: 210056
time(s): 412
digits: 15000
digits/s: 36.41
SD card will have file PIDIGITS.TXT with the output formatted with 32 digits/line, recall to stack with:
Up Arrow VIEW to see all digits.

NOTE: HPGCC binaries can be large. Best to store on SD card and run with:

3:pidf EVAL
Put that in a small UserRPL script and save to main memory.

You can hold down any key (but ON) to stop the run and collect partial output. When done exit with ON.


Get n from stack and compute n number of pi digits using
Spigot method from Pi Unleashed by Jorg Arndt & Christoph Haenel.

Mem allocated = ((n/4)+1)*14 * 4 bytes

Return to stack statistics, e.g.


bytes used: 70056
time(s): 46
digits: 5000
digits/s: 108.70


bytes used: 210056
time(s): 412
digits: 15000
digits/s: 36.41

Only HP specific comments, read book for algorithm details.


#include <hpgcc49.h> //the standard HP lib

int main(void){
int *a;
int b;
int c;
int d = 0;
int e = 0;
int f = 10000;
int g;
int h = 0;
int start;
int end;
int cc = 0;
char buf[40];
int ndigits;
FILE *fh;
char *filename = "pidigits.txt";

sys_slowOff(); //max speed
clear_screen(); //clear the screen

if((fh = fopen(filename,"w"))) {
else {
printf("Error opening %s\n",filename);
sys_slowOn(); //normal speed
WAIT_CANCEL; //loop until ON pressed

ndigits = sat_pop_zint_llong(); //get ndigits from stack, must be int > 0
if(ndigits > 0) {
else {
printf("Number of PI digits must be an\ninteger > 0!\n");
sys_slowOn(); //normal speed
WAIT_CANCEL; //loop until ON pressed

start = sys_RTC_seconds(); //get start time in seconds since 1/1/1970
while ((b=c-=14) > 0) { //logic, compute 4 digits of pi at a time then display
while(--b > 0) {
d *= b;
if (h == 0)
d += 2000 * f;
d += a[b] * f;
a[b] = d % g;
d /= g;
printf("%04d", e + d/f);
fprintf(fh,"%04d", e + d/f);
if(cc % 32 == 0) {
if(keyb_isAnyKeyPressed()) //hold any key to stop, do not use ON
d = e = d % f;
h = 4;
end = sys_RTC_seconds(); //get end time in seconds since 1/1/1970

sprintf(buf,"bytes used: %d",(ndigits/4+1)*14*(int)sizeof(*a));
sat_stack_push_string(buf); //push string to stack

sprintf(buf,"time(s): %d",end-start);
printf(" %s\n",buf);
sat_stack_push_string(buf); //push string to stack

sprintf(buf,"digits: %d",cc);
printf(" %s\n",buf);
sat_stack_push_string(buf); //push string to stack

if(end-start == 0)
sprintf(buf,"digits/s: NAN");
sprintf(buf,"digits/s: %.2f",(float)cc/(float)(end-start));
printf(" %s",buf);
sat_stack_push_string(buf); //push string to stack

sys_slowOn(); //normal speed
WAIT_CANCEL; //loop until ON pressed

Edited: 24 Sept 2007, 11:37 a.m. after one or more responses were posted


I have a xerox of an old paper about the computation of Pi, titled "Some Comments on a NORC Computation of Pi". I think the paper dates from around 1956.

The authors say in the first paragraph:

"Among the problems suggested as demonstration routines for the NORC (Naval Ordnance Research Computer) was the calculation of Pi to a large number of digits. In 1949, Pi was calculated to 2035 digits on the ENIAC. The present computation on the NORC, which was carried out by the authors at the Watson Scientific Computing Laboratory, produced 3089 digits. This limit was chosen since the entire calculation could be contained in the NORC's high speed memory (2000 locations). The program was designed to produce any number of digits up to this limit."

They say that the computation took 13 minutes.

I wonder what kind of memory the NORC had? All of "2000 locations". And how much power was consumed during the computation?

In 2007, using the power provided by a few penlight cells, Pi can be computed to 15,000 digits in about 7 minutes. On a pocket sized computer with over 200,000 memory "locations"!

Mathematica keeps the first 10,000 digits of Pi pre-calculated and stored in memory. So if a calculation needs up to 10,000 digits, there's no delay in calculating them; they're just fetched from memory.

If more digits are needed, they're calculated using the Chudnovsky formula. On my laptop, Mathematica takes 3.5 seconds to calculate 1,000,000 digits of Pi, and 58 seconds to calculate 10,000,000 digits. And, no doubt, using far less power than the ENIAC or NORC did.

This is progress.


The Spigot method isn't the fastest. But it is small, does not require MP or FP math (integers only), and you get to watch the action.

If I have time I'll try out Chudnovsky.


Many thanks for your advice. Do you know if the program can be run also in a HP-49g?(not a HP-49g+)

Juan Pablo


AFAIK, the 49g uses the Saturn CPU. You need an ARM-based unit (49g+/50g).

Possibly Related Threads...
Thread Author Replies Views Last Post
  [OT] Mathematica free for Raspberry PI BruceH 32 6,046 11-23-2013, 05:24 AM
Last Post: Nick_S
  Computing pi with the PC-1300S Kiyoshi Akima 0 786 11-17-2013, 12:24 AM
Last Post: Kiyoshi Akima
  Calculating Pi LHH 9 2,139 09-27-2013, 10:50 PM
Last Post: Gerson W. Barbosa
  Visualization of pi Bruce Bergman 13 2,798 08-17-2013, 05:00 PM
Last Post: Howard Owen
  OT: Happy Pi Day! Eddie W. Shore 13 2,629 03-22-2013, 10:44 AM
Last Post: Les Koller
  Totally OT ... Pi Day for my car Maximilian Hohmann 18 3,250 03-10-2013, 01:15 PM
Last Post: chris smith
  [WP34S] A funny bug in Pi (prod) Eduardo Duenez 3 1,062 01-28-2013, 03:41 AM
Last Post: Walter B
  28S Pi Functionality Matt Fegenbush 3 1,144 10-17-2012, 02:15 AM
Last Post: Nick_S
  Books on computing Elementary Functions Nick_S 4 1,218 09-14-2012, 07:33 AM
Last Post: David Hayden
  Obtaining More Decimal Digits (50g) Eddie W. Shore 3 1,109 09-13-2012, 05:38 PM
Last Post: Gilles Carpentier

Forum Jump: