{"id":779,"date":"2020-12-03T17:46:50","date_gmt":"2020-12-03T15:46:50","guid":{"rendered":"http:\/\/www.bashpi.org\/?page_id=779"},"modified":"2020-12-31T17:55:16","modified_gmt":"2020-12-31T15:55:16","slug":"calculating-pi-%cf%80-with-bash","status":"publish","type":"page","link":"https:\/\/www.bashpi.org\/?page_id=779","title":{"rendered":"Calculating Pi (\u03c0) with bash"},"content":{"rendered":"\n<p>I just created this page for people who ended up in this site searching for ways to get pi value with bash shell. There are multiple ways for calculation but I like following:<\/p>\n\n\n\n<p>1. make sure you have package <em>bc<\/em> installed. It comes from package named &#8220;bc&#8221; on debian.<br>2. run command below where parameter scale is number of decimal places after comma.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export BC_LINE_LENGTH=0;bc -lq &lt;&lt;&lt; \"scale=1000;4*a(1)\"\n<\/code><\/pre>\n\n\n\n<p>Alternatively you could make a shellscript like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nDP=1000\nexport BC_LINE_LENGTH=0\n\npi=`bc -lq &lt;&lt;&lt; \"scale=${DP};4*a(1)\"`\n\necho ${pi}\n\nexit 0\n<\/code><\/pre>\n\n\n\n<p>Environment variable BC_LINE_LENGTH with 0 value is needed to disable result line splitting with backslash and newline.<\/p>\n\n\n\n<p>Check out also how to do <a href=\"https:\/\/www.bashpi.org\/?page_id=910\" data-type=\"page\" data-id=\"910\">other calculations in bash<\/a><\/p>\n\n\n\n<p>If you found this useful, say thanks, click on some banners or <a href=\"http:\/\/www.bashpi.org\/?page_id=105\">donate<\/a>, I can always use some beer money.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just created this page for people who ended up in this site searching for ways to get pi value with bash shell. There are multiple ways for calculation but I like following: 1. make sure you have package bc installed. It comes from package named &#8220;bc&#8221; on debian.2. run command below where parameter scale [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-779","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=779"}],"version-history":[{"count":2,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/779\/revisions"}],"predecessor-version":[{"id":1094,"href":"https:\/\/www.bashpi.org\/index.php?rest_route=\/wp\/v2\/pages\/779\/revisions\/1094"}],"wp:attachment":[{"href":"https:\/\/www.bashpi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}