Categories
Technical

Tech Short: Generate Pi to a given number in Linux

Its Pi day – Saturday, March 14 is Pi Day 2015

Why not do something cool in Linux like generate pi to a given number of decimal places.  This can be done by using the tool  bc (Bench Calculator) which is installed in most Linux distributions I have used.

The following command will calculate π to 10 decimal places

echo "scale=10; 4*a(1)" | bc -l

The results:  3.1415926532

So enjoy some pi

 

More and Resources Use –
scale=100 – this specifies the number of decimal places to use for the result
4*a(1) – this returns the arctangent of 1 [which equals 45°: 45 x (π/180), or ¼π] then multiplies by 4 to get π.
bc -l – pipe the complete function string into the bc utility, -l specifies to load the standard math library that’s needed for the arctangent function, a().

Info from: http://superuser.com/questions/275516/how-can-i-generate-pi-to-a-given-number-of-decimal-places-from-a-script

One reply on “Tech Short: Generate Pi to a given number in Linux”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.