<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Mathematical constant e generator in Java</title>
	<atom:link href="http://squarism.com/2003/04/30/mathematical-constant-e-generator-in-java/feed/" rel="self" type="application/rss+xml" />
	<link>http://squarism.com/2003/04/30/mathematical-constant-e-generator-in-java/</link>
	<description>until lambs become lions</description>
	<lastBuildDate>Sat, 04 Feb 2012 09:25:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: James</title>
		<link>http://squarism.com/2003/04/30/mathematical-constant-e-generator-in-java/comment-page-1/#comment-5</link>
		<dc:creator>James</dc:creator>
		<pubDate>Thu, 01 May 2003 19:57:52 +0000</pubDate>
		<guid isPermaLink="false">http://squarism.com/2003/04/30/mathematical-constant-e-generator-in-java/#comment-5</guid>
		<description>Try this optimization

(Forgive the formatting)
// -- Add a constant variable 
public static final BigInteger BIG_INT_CONSTANT = BigInteger.valueOf(i);

 
/* the useful stuff */
private BigDecimal doCalculation() 
{
    BigInteger factorialTotal = new BigInteger(&quot;1&quot;);
    BigDecimal bigE = new BigDecimal(&quot;1&quot;);
 
    for (int i = 0; i &lt; numberOfDigits; i++) 
    {
        /*
         * The Following adheres to the formula:
         * 
         * e = 1/0! + 1/1! + 1/2! + 1/3! + 1/4! + ...
         * 
         */
        
        // increment factorial by multiplying itself by itself  
        factorialTotal = factorialTotal.add(
            factorialTotal.multiply(BIG_INT_CONSTANT));
        // --                               ^^^^^^^^^^^^^     Use the constant variable     
        // e grows and becomes more accurate
        bigE = bigE.add(
            BIG_INT_CONSTANT.divide(new BigDecimal(factorialTotal), numberOfDigits, BigDecimal.ROUND_HALF_UP));
        // --                                                                 ^^^^^^^^^     Use the BigInteger parameter constructor     

    }
    
    return bigE;
}


</description>
		<content:encoded><![CDATA[<p>Try this optimization</p>
<p>(Forgive the formatting)<br />
// &#8212; Add a constant variable<br />
public static final BigInteger BIG_INT_CONSTANT = BigInteger.valueOf(i);</p>
<p>/* the useful stuff */<br />
private BigDecimal doCalculation()<br />
{<br />
    BigInteger factorialTotal = new BigInteger(&#8220;1&#8243;);<br />
    BigDecimal bigE = new BigDecimal(&#8220;1&#8243;);</p>
<p>    for (int i = 0; i &lt; numberOfDigits; i++)<br />
    {<br />
        /*<br />
         * The Following adheres to the formula:<br />
         *<br />
         * e = 1/0! + 1/1! + 1/2! + 1/3! + 1/4! + &#8230;<br />
         *<br />
         */</p>
<p>        // increment factorial by multiplying itself by itself<br />
        factorialTotal = factorialTotal.add(<br />
            factorialTotal.multiply(BIG_INT_CONSTANT));<br />
        // &#8212;                               ^^^^^^^^^^^^^     Use the constant variable<br />
        // e grows and becomes more accurate<br />
        bigE = bigE.add(<br />
            BIG_INT_CONSTANT.divide(new BigDecimal(factorialTotal), numberOfDigits, BigDecimal.ROUND_HALF_UP));<br />
        // &#8212;                                                                 ^^^^^^^^^     Use the BigInteger parameter constructor     </p>
<p>    }</p>
<p>    return bigE;<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

