Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Tip: Calculate Pi on Pi Day

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
Hallvor
Global Moderator
Global Moderator
Posts: 2042
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 149 times
Been thanked: 212 times

Tip: Calculate Pi on Pi Day

#1 Post by Hallvor »

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
[HowTo] Install and configure Debian bookworm
Debian 12 | KDE Plasma | ThinkPad T440s | 4 × Intel® Core™ i7-4600U CPU @ 2.10GHz | 12 GiB RAM | Mesa Intel® HD Graphics 4400 | 1 TB SSD

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

Re: Tip: Calculate Pi on Pi Day

#2 Post by AR15USR »

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

#3 Post by AR15USR »

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

User avatar
Hallvor
Global Moderator
Global Moderator
Posts: 2042
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 149 times
Been thanked: 212 times

Re: Tip: Calculate Pi on Pi Day

#4 Post by Hallvor »

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

That is a great tip! It was very fast.
[HowTo] Install and configure Debian bookworm
Debian 12 | KDE Plasma | ThinkPad T440s | 4 × Intel® Core™ i7-4600U CPU @ 2.10GHz | 12 GiB RAM | Mesa Intel® HD Graphics 4400 | 1 TB SSD

User avatar
Bloom
df -h | grep > 90TiB
df -h | grep > 90TiB
Posts: 504
Joined: 2017-11-11 12:23
Been thanked: 26 times

Re: Tip: Calculate Pi on Pi Day

#5 Post by Bloom »

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

#6 Post by AR15USR »

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

Post Reply