<?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>No movement is faster than no movement</description>
	<lastBuildDate>Sun, 07 Mar 2010 15:17:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Martin Ankerl</title>
		<link>http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/comment-page-1/#comment-6602</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-6602</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' 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-page-1/#comment-6601</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-6601</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' 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-page-1/#comment-6476</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-6476</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' 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-page-1/#comment-5984</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-5984</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-page-1/#comment-5913</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-5913</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-page-1/#comment-5616</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-5616</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-page-1/#comment-512</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-512</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-page-1/#comment-511</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-511</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() &#38;mdash; Martin Ankerl</title>
		<link>http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/comment-page-1/#comment-510</link>
		<dc:creator>Exponential Functions: Benchmarks, 11 Times Faster Math.pow() &#38;mdash; Martin Ankerl</dc:creator>
		<pubDate>Mon, 12 Feb 2007 15:26:58 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=82#comment-510</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>
	<item>
		<title>By: Martin Ankerl</title>
		<link>http://martin.ankerl.com/2007/02/11/optimized-exponential-functions-for-java/comment-page-1/#comment-509</link>
		<dc:creator>Martin Ankerl</dc:creator>
		<pubDate>Mon, 12 Feb 2007 08:35:40 +0000</pubDate>
		<guid isPermaLink="false">http://martin.ankerl.com/?p=82#comment-509</guid>
		<description>Here are some benchmarks from a Pentium IV, doing 20 million calculations. On this machine I get an even better performance than stated above. I use Sun&#039;s JRE 1.5.0_08.

6.233 sec, Math.log(val)
0.531 sec, 6*(x-1)/ (x + 1 + 4*(Math.sqrt(x)))

5.920 sec, Math.exp()
1.108 sec, exp optimized with IEEE 754 trick

15.967 sec, Math.pow(a, b)
11.014 sec, e^(b * log(a))
7.607 sec, e^(b * log(a)) + IEEE 754 trick
2.109 sec, e^(b * log(a)) + IEEE 754 trick + LOG approximation
1.827 sec, simplified everything</description>
		<content:encoded><![CDATA[<p>Here are some benchmarks from a Pentium IV, doing 20 million calculations. On this machine I get an even better performance than stated above. I use Sun&#8217;s JRE 1.5.0_08.</p>
<p>6.233 sec, Math.log(val)<br />
0.531 sec, 6*(x-1)/ (x + 1 + 4*(Math.sqrt(x)))</p>
<p>5.920 sec, Math.exp()<br />
1.108 sec, exp optimized with IEEE 754 trick</p>
<p>15.967 sec, Math.pow(a, b)<br />
11.014 sec, e^(b * log(a))<br />
7.607 sec, e^(b * log(a)) + IEEE 754 trick<br />
2.109 sec, e^(b * log(a)) + IEEE 754 trick + LOG approximation<br />
1.827 sec, simplified everything</p>
]]></content:encoded>
	</item>
</channel>
</rss>
