<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Alien Pastures &#187; oneliner</title>
	<atom:link href="http://alien.slackbook.org/blog/tag/oneliner/feed/" rel="self" type="application/rss+xml" />
	<link>http://alien.slackbook.org/blog</link>
	<description>My thoughts on Slackware, life and everything</description>
	<lastBuildDate>Mon, 06 Feb 2012 00:27:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Calculating PI</title>
		<link>http://alien.slackbook.org/blog/calculating-pi/</link>
		<comments>http://alien.slackbook.org/blog/calculating-pi/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 16:34:35 +0000</pubDate>
		<dc:creator>alienbob</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[oneliner]]></category>

		<guid isPermaLink="false">http://alien.slackbook.org/blog/?p=105</guid>
		<description><![CDATA[The Internet is full of &#8220;one-liners&#8221; and if you search a bit, you can find many. A one-liner typically means (a chain of) commands that produce useful results quickly. I came across a nice one-liner just now. The &#8220;binary calculator&#8221; or bc is a powerful UNIX tool. Calculating the value of PI with an arbitrary [...]]]></description>
			<content:encoded><![CDATA[<p>The Internet is full of &#8220;one-liners&#8221; and if you search a bit, you can find many. A one-liner typically means (a chain of) commands that produce useful results quickly.</p>
<p>I came across a nice one-liner just now. The &#8220;binary calculator&#8221; or bc is a powerful UNIX tool. Calculating the value of <strong>PI</strong> with an arbitrary number of decimals (the number of decimals only restricted by the power of your OS, available RAM or internal limitations of the program) goes like this:</p>
<blockquote>
<h4 style="text-align: left;"><strong>echo &#8220;scale=XXXX;4*a(1)&#8221; | bc -l<br />
</strong></h4>
</blockquote>
<p>Where &#8220;XXXX&#8221; is the number of digits you want to calculate. Calling bc with the &#8220;<strong>-l</strong>&#8221; parameter causes bc to load it&#8217;s mathematical library. The function &#8220;<strong>a()</strong>&#8221; is the arctangent function.</p>
<p>Let&#8217;s say you need the value of <strong>PI</strong> with an accuracy of a thousand decimals.</p>
<pre><span style="color: #3366ff;">$ echo "scale=1000;4*a(1)" | bc -l</span></pre>
<pre><span style="color: #3366ff;">3.141592653589793238462643383279502884197169399375105820974944592307\</span></pre>
<pre><span style="color: #3366ff;">81640628620899862803482534211706798214808651328230664709384460955058\</span></pre>
<pre><span style="color: #3366ff;">22317253594081284811174502841027019385211055596446229489549303819644\</span></pre>
<pre><span style="color: #3366ff;">28810975665933446128475648233786783165271201909145648566923460348610\</span></pre>
<pre><span style="color: #3366ff;">45432664821339360726024914127372458700660631558817488152092096282925\</span></pre>
<pre><span style="color: #3366ff;">40917153643678925903600113305305488204665213841469519415116094330572\</span></pre>
<pre><span style="color: #3366ff;">70365759591953092186117381932611793105118548074462379962749567351885\</span></pre>
<pre><span style="color: #3366ff;">75272489122793818301194912983367336244065664308602139494639522473719\</span></pre>
<pre><span style="color: #3366ff;">07021798609437027705392171762931767523846748184676694051320005681271\</span></pre>
<pre><span style="color: #3366ff;">45263560827785771342757789609173637178721468440901224953430146549585\</span></pre>
<pre><span style="color: #3366ff;">37105079227968925892354201995611212902196086403441815981362977477130\</span></pre>
<pre><span style="color: #3366ff;">99605187072113499999983729780499510597317328160963185950244594553469\</span></pre>
<pre><span style="color: #3366ff;">08302642522308253344685035261931188171010003137838752886587533208381\</span></pre>
<pre><span style="color: #3366ff;">42061717766914730359825349042875546873115956286388235378759375195778\</span></pre>
<pre><span style="color: #3366ff;">18577805321712268066130019278766111959092164201988</span></pre>
<p>Isn&#8217;t this fun? And on my old dual P2/233MHz server, this took roughly eight seconds.</p>
<p>Now, to compare the usefulness of the Linux platform to good old Solaris, this is what you get on Solaris 8:</p>
<pre><span style="color: #3366ff;">$ echo "scale=1000;4*a(1)" | bc -l
scale factor is too large
3.14159265358979323844</span></pre>
<p>Cheers, Eric</p>
]]></content:encoded>
			<wfw:commentRss>http://alien.slackbook.org/blog/calculating-pi/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

