March 14 2013 Thursday
Happy Pi Day present: Pi Calculator for XPages...
Today is the "Pi Day"...
Last week I was playing with Threads and Jobs project from OpenNTF. I needed a very long job to be run n the server-side. I have thought calculating pi digits would be a cool selection :)
I found a Javascript-based Spigot algorithm by Stephen R. Schmitt and easily converted to Java (sorry about the code!).
Notice that, on an average machine it calculates 10,000 digits in less than a minute. Now consider, ENIAC has calculated 2037 digits in 70 hours in 1949!
However, to calculate trillion digits would be tough with this algorithm. Because we need a large String buffer and a large integer array for calculation. Integer array is around 3.5 times the digit count and string buffer has one chars per digit. So we are limited with the heap size. In a non-XPages environment, if you don't keep string buffer, you would be able to calculate 2.5 million digits with standard memory :)
Anyway, it was fun and I wanted to share it. Here is the screencast:
You can download the database here.
Last week I was playing with Threads and Jobs project from OpenNTF. I needed a very long job to be run n the server-side. I have thought calculating pi digits would be a cool selection :)
I found a Javascript-based Spigot algorithm by Stephen R. Schmitt and easily converted to Java (sorry about the code!).
Notice that, on an average machine it calculates 10,000 digits in less than a minute. Now consider, ENIAC has calculated 2037 digits in 70 hours in 1949!
However, to calculate trillion digits would be tough with this algorithm. Because we need a large String buffer and a large integer array for calculation. Integer array is around 3.5 times the digit count and string buffer has one chars per digit. So we are limited with the heap size. In a non-XPages environment, if you don't keep string buffer, you would be able to calculate 2.5 million digits with standard memory :)
Anyway, it was fun and I wanted to share it. Here is the screencast:
You can download the database here.
Comments (3)
Stephen,
I just forgot to change ACL before submitting.
Design is not locked but if you place the database into the server, you won't be designer by default so you experience this problem. You can either;
- Open the database in you notes client locally, so ACL will be overriden.
- Or open the database on server in Full Access Mode.
- Or create a database copy by unchecking ACL in "New Copy" dialog
Either way, you can add yourself as the manager and you can play with it.
Sorry :)
New copy worked. Thanks for the quick response.
Nothing to be sorry about :)