<?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: Optimized Exponential Functions for Java</title>
	<atom:link href="http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/feed/" rel="self" type="application/rss+xml" />
	<link>http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/</link>
	<description>Chunky bacon!!</description>
	<lastBuildDate>Wed, 08 Feb 2012 16:00:41 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Dick Rochester</title>
		<link>http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/#comment-2278</link>
		<dc:creator>Dick Rochester</dc:creator>
		<pubDate>Sat, 04 Jun 2011 01:37:42 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=82#comment-2278</guid>
		<description>I have inherited some code from a former employee. He has some code he calls 

double powa(double x, double a)

which he says compute x^a for a close to 1.0.

The code is

double powa(double x, double a)
{
   double lnx = log(x);
   double am1 = a - 1;
   double product = lnx * am1;

   return (product + x * product^2 + x);
}

I at first thought he was using three terms of a Talor series about 1.0. However, it doesn&#039;t seem to be that.

Where did this come from. BTW, I tested it and it does work, i.e. gives the same result as pow(x,a).</description>
		<content:encoded><![CDATA[<p>I have inherited some code from a former employee. He has some code he calls </p>
<p>double powa(double x, double a)</p>
<p>which he says compute x^a for a close to 1.0.</p>
<p>The code is</p>
<p>double powa(double x, double a)<br />
{<br />
   double lnx = log(x);<br />
   double am1 = a &#8211; 1;<br />
   double product = lnx * am1;</p>
<p>   return (product + x * product^2 + x);<br />
}</p>
<p>I at first thought he was using three terms of a Talor series about 1.0. However, it doesn&#8217;t seem to be that.</p>
<p>Where did this come from. BTW, I tested it and it does work, i.e. gives the same result as pow(x,a).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Ankerl</title>
		<link>http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/#comment-222</link>
		<dc:creator>Martin Ankerl</dc:creator>
		<pubDate>Thu, 21 Jan 2010 20:34:20 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=82#comment-222</guid>
		<description>glad that it&#039;s working :)</description>
		<content:encoded><![CDATA[<p>glad that it&#8217;s working <img src="http://martin.ankerl.com/wp-includes/images/smilies/icon_smile.gif?9d7bd4" alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jarek</title>
		<link>http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/#comment-221</link>
		<dc:creator>Jarek</dc:creator>
		<pubDate>Thu, 21 Jan 2010 20:22:17 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=82#comment-221</guid>
		<description>I confirm that those work with J2ME. Thanks to your math approximations I&#039;ve been able to run Speex voice decoding on a mobile with a decent performance :)</description>
		<content:encoded><![CDATA[<p>I confirm that those work with J2ME. Thanks to your math approximations I&#8217;ve been able to run Speex voice decoding on a mobile with a decent performance <img src="http://martin.ankerl.com/wp-includes/images/smilies/icon_smile.gif?9d7bd4" alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Axeia</title>
		<link>http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/#comment-220</link>
		<dc:creator>Axeia</dc:creator>
		<pubDate>Fri, 01 Jan 2010 15:36:08 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=82#comment-220</guid>
		<description>The &lt;strong&gt;exp&lt;/strong&gt; functions also seems to be working quite for &lt;strong&gt; J2ME&lt;/strong&gt; which is lacking J2ME.

So if you&#039;re writing say a game with projectiles traveling a certain trajectory it&#039;s good enough :)</description>
		<content:encoded><![CDATA[<p>The <strong>exp</strong> functions also seems to be working quite for <strong> J2ME</strong> which is lacking J2ME.</p>
<p>So if you&#8217;re writing say a game with projectiles traveling a certain trajectory it&#8217;s good enough <img src="http://martin.ankerl.com/wp-includes/images/smilies/icon_smile.gif?9d7bd4" alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nosredna</title>
		<link>http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/#comment-219</link>
		<dc:creator>Nosredna</dc:creator>
		<pubDate>Sun, 16 Aug 2009 14:12:12 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=82#comment-219</guid>
		<description>I think a is just mantissa. I&#039;m guessing John started changing the variable name and forgot what he was doing.</description>
		<content:encoded><![CDATA[<p>I think a is just mantissa. I&#8217;m guessing John started changing the variable name and forgot what he was doing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michel Hummel</title>
		<link>http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/#comment-218</link>
		<dc:creator>Michel Hummel</dc:creator>
		<pubDate>Thu, 11 Jun 2009 14:42:45 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=82#comment-218</guid>
		<description>&lt;a href=&quot;#comment-5616&quot; rel=&quot;nofollow&quot;&gt;@John&lt;/a&gt;
Hello,
i&#039;m very interested by the accuracy optimization you suggested but i don&#039;t undertand what is variable &quot;a&quot; in the expression :
error = (error - a * a) / 186;

Could you explain it please

Thanks
Michel Hummel</description>
		<content:encoded><![CDATA[<p><a href="#comment-5616" rel="nofollow">@John</a><br />
Hello,<br />
i&#8217;m very interested by the accuracy optimization you suggested but i don&#8217;t undertand what is variable &#8220;a&#8221; in the expression :<br />
error = (error &#8211; a * a) / 186;</p>
<p>Could you explain it please</p>
<p>Thanks<br />
Michel Hummel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/#comment-217</link>
		<dc:creator>John</dc:creator>
		<pubDate>Tue, 24 Feb 2009 14:04:45 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=82#comment-217</guid>
		<description>I have used the same trick for float, not double, with some slight modification to the constants to suite IEEE754 float format. The first constant for float is 1&lt;&lt;23/log(2) and the second is 127&lt;&lt;23 (for double they are 1&lt;&lt;20/log(2) and 1023&lt;&lt;20).

You don&#039;t need to do the addition as floating point, I have move the braces around...
&lt;pre&gt;public static double exp(double val) {
    final long tmp = (long) (1512775 * val) + (1072693248 - 60801);
    return Double.longBitsToDouble(tmp &lt;&lt; 32);
}&lt;/pre&gt;

Additionally if you analyse the error there is a correlation to the mantissa of the result, which you can then correct for. The error is approximately (mantissa - mantissa^2)/2.9. Doing this all as integer math in fixed point format you get.

&lt;pre&gt;public static double exp(double val) {
    final long tmp = (long) (1512775 * val) + 1072693248;
    final long mantissa = tmp &amp; 0x000FFFFF;
    int error = mantissa &gt;&gt; 7;   // remove chance of overflow
    error = (error - a * a) / 186; // subtract mantissa^2 * 64
                                   // 64 / 186 = 1/2.90625
    return Double.longBitsToDouble((tmp - error) &lt;&lt; 32);
}&lt;/pre&gt;

PS hope this is valid Java, I converted from C.

The explain the shifting. The mantissa has 20 bits to the right of the decimal place. a is formed by shift right 7, leaving 13 bits to the right. When a is squared you double the number of decimal bits arriving at 26. Which is 20 bits times the scaling factor or 64 (6 bits). Now a squared matches error so the subtraction is valid.</description>
		<content:encoded><![CDATA[<p>I have used the same trick for float, not double, with some slight modification to the constants to suite IEEE754 float format. The first constant for float is 1&lt;&lt;23/log(2) and the second is 127&lt;&lt;23 (for double they are 1&lt;&lt;20/log(2) and 1023&lt;&lt;20).</p>
<p>You don&#8217;t need to do the addition as floating point, I have move the braces around&#8230;</p>
<pre>public static double exp(double val) {
    final long tmp = (long) (1512775 * val) + (1072693248 - 60801);
    return Double.longBitsToDouble(tmp &lt;&lt; 32);
}</pre>
<p>Additionally if you analyse the error there is a correlation to the mantissa of the result, which you can then correct for. The error is approximately (mantissa &#8211; mantissa^2)/2.9. Doing this all as integer math in fixed point format you get.</p>
<pre>public static double exp(double val) {
    final long tmp = (long) (1512775 * val) + 1072693248;
    final long mantissa = tmp &amp; 0x000FFFFF;
    int error = mantissa &gt;&gt; 7;   // remove chance of overflow
    error = (error - a * a) / 186; // subtract mantissa^2 * 64
                                   // 64 / 186 = 1/2.90625
    return Double.longBitsToDouble((tmp - error) &lt;&lt; 32);
}</pre>
<p>PS hope this is valid Java, I converted from C.</p>
<p>The explain the shifting. The mantissa has 20 bits to the right of the decimal place. a is formed by shift right 7, leaving 13 bits to the right. When a is squared you double the number of decimal bits arriving at 26. Which is 20 bits times the scaling factor or 64 (6 bits). Now a squared matches error so the subtraction is valid.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Optimized pow() approximation for Java and C / C++ by Martin Ankerl</title>
		<link>http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/#comment-216</link>
		<dc:creator>Optimized pow() approximation for Java and C / C++ by Martin Ankerl</dc:creator>
		<pubDate>Thu, 04 Oct 2007 22:48:13 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=82#comment-216</guid>
		<description>[...] I have already written about approximations of e^x, log(x) and pow(a, b) in my post Optimized Exponential Functions for Java. Now I have more  . In particular, the pow() function is now even faster, simpler, and more accurate. Without further ado, I proudly give you the brand new approximation: [...]</description>
		<content:encoded><![CDATA[<p>[...] I have already written about approximations of e^x, log(x) and pow(a, b) in my post Optimized Exponential Functions for Java. Now I have more  . In particular, the pow() function is now even faster, simpler, and more accurate. Without further ado, I proudly give you the brand new approximation: [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DoctorEternal</title>
		<link>http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/#comment-215</link>
		<dc:creator>DoctorEternal</dc:creator>
		<pubDate>Thu, 22 Feb 2007 01:12:08 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=82#comment-215</guid>
		<description>Thanks for this. Always good to get more performance tweaking out of Java. I use Processing for game dev in Java, and even with it&#039;s use of Jikes, it could still use a boost.

Dr.E
http://www.turingshop.com/reports/01Java/</description>
		<content:encoded><![CDATA[<p>Thanks for this. Always good to get more performance tweaking out of Java. I use Processing for game dev in Java, and even with it&#8217;s use of Jikes, it could still use a boost.</p>
<p>Dr.E<br />
<a href="http://www.turingshop.com/reports/01Java/" rel="nofollow">http://www.turingshop.com/reports/01Java/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Exponential Functions: Benchmarks, 11 Times Faster Math.pow() &#8212; Martin Ankerl</title>
		<link>http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/#comment-214</link>
		<dc:creator>Exponential Functions: Benchmarks, 11 Times Faster Math.pow() &#8212; Martin Ankerl</dc:creator>
		<pubDate>Mon, 12 Feb 2007 15:26:58 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=82#comment-214</guid>
		<description>[...] I have updated the code for the Math.pow() approximation, now it is 11 times faster on my Pentium IV. Read it this. [...]</description>
		<content:encoded><![CDATA[<p>[...] I have updated the code for the Math.pow() approximation, now it is 11 times faster on my Pentium IV. Read it this. [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 1/3 queries in 0.008 seconds using disk: basic
Object Caching 444/445 objects using disk: basic

Served from: martin.ankerl.com @ 2012-02-08 22:44:45 -->
