<?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: Inlining Math Functions</title>
	<atom:link href="http://jacksondunstan.com/articles/445/feed" rel="self" type="application/rss+xml" />
	<link>http://jacksondunstan.com/articles/445</link>
	<description>Mastering AS3</description>
	<lastBuildDate>Mon, 14 May 2012 17:02:12 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: jackson</title>
		<link>http://jacksondunstan.com/articles/445/comment-page-1#comment-391</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Mon, 16 Nov 2009 23:00:14 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=445#comment-391</guid>
		<description>You&#039;re right that I&#039;ve already tested that in my article on &lt;a href=&quot;/articles/413&quot; rel=&quot;nofollow&quot;&gt;function performance&lt;/a&gt;. The static calls would add some time to it. If you were going to use a lot of math functions all in one place you might use non-static versions like this:

&lt;pre lang=&quot;actionscript3&quot;&gt;
// Generate sin and cos tables (for example)
var sin:Dictionary = new Dictionary();
var cos:Dictionary = new Dictionary();
var math:JMath = JMath.instance;
for (var angle:Number = 0; angle &lt; 360; angle += 0.01)
{
    sin[angle] = math.sin(angle);
    cos[angle] = math.cos(angle);
}
&lt;/pre&gt;

The cost of the local variable and the static &lt;tt&gt;instance&lt;/tt&gt; getter are easily offset by the large number of static math calls you&#039;d save. It&#039;s pretty clean too.</description>
		<content:encoded><![CDATA[<p>You&#8217;re right that I&#8217;ve already tested that in my article on <a href="/articles/413" rel="nofollow">function performance</a>. The static calls would add some time to it. If you were going to use a lot of math functions all in one place you might use non-static versions like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// Generate sin and cos tables (for example)</span>
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">sin</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Dictionary</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Dictionary</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">cos</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Dictionary</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Dictionary</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> math<span style="color: #000066; font-weight: bold;">:</span>JMath = JMath<span style="color: #000066; font-weight: bold;">.</span>instance<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">angle</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #004993;">angle</span> <span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">360</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #004993;">angle</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000000; font-weight:bold;">0.01</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #004993;">sin</span><span style="color: #000000;">&#91;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#93;</span> = math<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sin</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #004993;">cos</span><span style="color: #000000;">&#91;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#93;</span> = math<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">cos</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">angle</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The cost of the local variable and the static <tt>instance</tt> getter are easily offset by the large number of static math calls you&#8217;d save. It&#8217;s pretty clean too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Og2t</title>
		<link>http://jacksondunstan.com/articles/445/comment-page-1#comment-390</link>
		<dc:creator>Og2t</dc:creator>
		<pubDate>Mon, 16 Nov 2009 22:52:19 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=445#comment-390</guid>
		<description>Very interesting Jackson, I am thinking of replacing Math class with JMath now :) Would you think the static method call will add a lot of microtime to the results? I think you&#039;ve done some tests for that before?</description>
		<content:encoded><![CDATA[<p>Very interesting Jackson, I am thinking of replacing Math class with JMath now :) Would you think the static method call will add a lot of microtime to the results? I think you&#8217;ve done some tests for that before?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Bloodhound Gang: The Case of the secret messege Pt.2 &#124; Contact Cases &#124; Discount Contact Lens Cases</title>
		<link>http://jacksondunstan.com/articles/445/comment-page-1#comment-384</link>
		<dc:creator>The Bloodhound Gang: The Case of the secret messege Pt.2 &#124; Contact Cases &#124; Discount Contact Lens Cases</dc:creator>
		<pubDate>Fri, 13 Nov 2009 15:43:43 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=445#comment-384</guid>
		<description>[...] Inlining Math Functions « JacksonDunstan.com [...]</description>
		<content:encoded><![CDATA[<p>[...] Inlining Math Functions « JacksonDunstan.com [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

