## Tip: Calculate Pi on Pi Day

Share your own howto's etc. Not for support questions!
Message
Author
Hallvor
Posts: 1181
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 3 times
Been thanked: 2 times

### Tip: Calculate Pi on Pi Day

14th of March is Pi Day. It is an annual celebration of the mathematical constant π (pi). If you want to calculate Pi, you can do it yourself with the following command, where the number after = is the number of decimals you want to calculate:

Code: Select all

``\$ echo "scale=1000; 4*a(1)" | bc -l``
If you want to calculate large amounts of data, I recommend saving the output to a text file. It can be done like this:

Code: Select all

``\$ echo "scale=1000; 4*a(1)" | bc -l > pi.txt``
Lenovo ThinkPad T440S, Intel Core i7-4600U CPU @ 2.10GHz, 8 GB RAM, 256 GB SSD, Debian Bullseye (KDE)
Lenovo ThinkPad X240, Intel Core i5-4300U CPU @ 2.90GHz, 8 GB RAM, 120 GB SSD, Debian Bullseye (KDE)

AR15USR
Posts: 10
Joined: 2020-05-07 02:02

### Re: Tip: Calculate Pi on Pi Day

Hey pretty cool, thanks for sharing..

Curious why the output wraps lines?

Code: Select all

``````3.141592653589793238462643383279502884197169399375105820974944592307\
81640628620899862803482534211706798214808651328230664709384460955058\
22317253594081284811174502841027019385211055596446229489549303819644\
28810975665933446128475648233786783165271201909145648566923460348610\``````
Debian 10 64-bit 4.19.0-13

AR15USR
Posts: 10
Joined: 2020-05-07 02:02

### Re: Tip: Calculate Pi on Pi Day

Well this got me thinking.... Found a program called 'y-cruncher' and just calculated pi to 500 million digits Fun..
Debian 10 64-bit 4.19.0-13

Hallvor
Posts: 1181
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 3 times
Been thanked: 2 times

### Re: Tip: Calculate Pi on Pi Day

I don't know why it does that...

That is a great tip! It was very fast.
Lenovo ThinkPad T440S, Intel Core i7-4600U CPU @ 2.10GHz, 8 GB RAM, 256 GB SSD, Debian Bullseye (KDE)
Lenovo ThinkPad X240, Intel Core i5-4300U CPU @ 2.90GHz, 8 GB RAM, 120 GB SSD, Debian Bullseye (KDE)

Bloom
Posts: 364
Joined: 2017-11-11 12:23

### Re: Tip: Calculate Pi on Pi Day

BC uses a default line length of 70 characters and will "wrap' when that is reached.
Export BC_LINE_LENGTH=0 if you don't want that. Example:

Code: Select all

``````export BC_LINE_LENGTH=0
echo "scale=1000; 4*a(1)" | bc -l
``````

AR15USR
Posts: 10
Joined: 2020-05-07 02:02

### Re: Tip: Calculate Pi on Pi Day

Bloom wrote:BC uses a default line length of 70 characters and will "wrap' when that is reached.
Export BC_LINE_LENGTH=0 if you don't want that. Example:

Code: Select all

``````export BC_LINE_LENGTH=0
echo "scale=1000; 4*a(1)" | bc -l
``````
Works great, thanks!
Debian 10 64-bit 4.19.0-13