# Calculation of Pi

Share:

I won’t be telling you what is Pi, it’s history…..blah blah…you can find this on Wikipedia. This place is for something interesting. Something that will make you think. Here’s an interesting unix command using binary calculator (bc). It will calculate the value of Pi with an arbitrary number of decimals (limited only by the limit of you RAM, OS). Sounds interesting haa….

`echo 'scale=1000;4*a(1)' | bc -l`

Have a look

Calculation of Pi

Now…how can we have fun with this…….think..think idea You can use this as a benchmark. Challenge you PC. I mean… increase the number of decimals that are echoed. In the above screenshot, 1000 decimals were echoed. It was instantaneous (depends upon your configuration)

System Configuration

Results of the tests that I conducted :

1. 1000 decimals – almost instantaneous
2. 2000 decimals – 2 sec 40 millisecond
3. 3000 decimals – 6 sec 50 millisecond
4. 5000 decimals – 21 sec 83 millisecond surprised shocking …it took i3 more than 21 seconds

Let’s make it more interesting and try this on the Raspberry Pi with default configuration (without Overclocking).

`time echo 'scale=1000;4*a(1)' | bc -l`

For Raspberry Pi :

1. 1000 decimal : 4 sec 37 millisecond
2. 2000 decimal : 24 sec 29 millisecond

Similarly you can conduct tests on your Raspberry Pi. The results that you get may differ from the one shown here, it depends on your Pi. The next step would be to overclock your  Pi & compare the results. This will  help you benchmark your Pi. We will be covering this in some other tutorial. For now that’s it from my side. Hope you enjoyed the “Pi” story.

If you have anything to add to this do let me know. Share your results so that others can compare & benchmark their Raspberry Pi.

Thank you for being patient. Have a good day.

1. Hobbit

Only you could have given Rasberry PI it’s due..:) Anyway keep up the good work.

• Dinesh Auti

Hahhaha….Thanks Hobbit :grin: .Pi deserves it.

2. eric

sorru when i tape these cmd i have answer : -bash; bc: command not found ..idéa ?
thank for help

• Dinesh Auti

Hi Eric,
Command not found in your case implies that “bc” is not installed on your machine. To install it in Ubuntu/Debian, type the following in the terminal `apt-get install bc`. If your are using CentOS/ RHEL/Fedora the command is `yum install bc`

• eric

Hi Dinesh
E: Could not open lock file /var/lib/dpkg/lock – open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

i am under raspbian, any other idea ? :)

• Dinesh Auti

Hey Eric,
Its a permission issue. It happened because the command that was executed did not administrative privileges, that is you were not root. To become root you need to add SUDO to the command. So now the command becomes `sudo apt-get install bc`.

Hope this helps you :-)

3. eric

i got soluce ..su and passwd and after all was OK. Many thank its fun

• Dinesh Auti

Enjoy :)