Tip: Calculate Pi on Pi Day

Share your own howto's etc. Not for support questions!

Tip: Calculate Pi on Pi Day

Postby Hallvor » 2020-03-14 11:40

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 Buster (KDE)
Lenovo ThinkPad X240, Intel Core i5-4300U CPU @ 2.90GHz, 8 GB RAM, 120 GB SSD, Debian Buster (KDE)
User avatar
Hallvor
 
Posts: 1062
Joined: 2009-04-16 18:35
Location: Norway

Re: Tip: Calculate Pi on Pi Day

Postby AR15USR » 2020-05-07 02:36

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-9
AR15USR
 
Posts: 6
Joined: 2020-05-07 02:02

Re: Tip: Calculate Pi on Pi Day

Postby AR15USR » 2020-05-07 04:08

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-9
AR15USR
 
Posts: 6
Joined: 2020-05-07 02:02

Re: Tip: Calculate Pi on Pi Day

Postby Hallvor » 2020-05-07 07:31

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 Buster (KDE)
Lenovo ThinkPad X240, Intel Core i5-4300U CPU @ 2.90GHz, 8 GB RAM, 120 GB SSD, Debian Buster (KDE)
User avatar
Hallvor
 
Posts: 1062
Joined: 2009-04-16 18:35
Location: Norway

Re: Tip: Calculate Pi on Pi Day

Postby Bloom » 2020-05-07 08:37

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
User avatar
Bloom
 
Posts: 267
Joined: 2017-11-11 12:23

Re: Tip: Calculate Pi on Pi Day

Postby AR15USR » 2020-05-07 17:05

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-9
AR15USR
 
Posts: 6
Joined: 2020-05-07 02:02


Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 1 guest

fashionable