<?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: Avoid ints in ActionScript</title>
	<atom:link href="http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/</link>
	<description>music, technology, interfaces</description>
	<lastBuildDate>Sun, 29 Jan 2012 05:22:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Sho</title>
		<link>http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/comment-page-1/#comment-362287</link>
		<dc:creator>Sho</dc:creator>
		<pubDate>Thu, 08 Sep 2011 15:40:53 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/#comment-362287</guid>
		<description>Hi Chris. Is that you?

Anyway, the info on this page is old, and I&#039;m sure that the performance characteristics are different now.

Also, incrementing integers and using them for array indexing was always (slightly) faster than the same operations with Number. It was always things like division where int was being converted to Number and back again in order to have consistent behavior in all edge cases.</description>
		<content:encoded><![CDATA[<p>Hi Chris. Is that you?</p>
<p>Anyway, the info on this page is old, and I&#8217;m sure that the performance characteristics are different now.</p>
<p>Also, incrementing integers and using them for array indexing was always (slightly) faster than the same operations with Number. It was always things like division where int was being converted to Number and back again in order to have consistent behavior in all edge cases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christopher Cantrell</title>
		<link>http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/comment-page-1/#comment-362277</link>
		<dc:creator>Christopher Cantrell</dc:creator>
		<pubDate>Thu, 08 Sep 2011 14:38:14 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/#comment-362277</guid>
		<description>The adobe-created classes like ArrayList use &quot;int&quot; instead of &quot;Number&quot; for loop counts and list indices. I figure they know what they are doing; I&#039;ll follow suit.</description>
		<content:encoded><![CDATA[<p>The adobe-created classes like ArrayList use &#8220;int&#8221; instead of &#8220;Number&#8221; for loop counts and list indices. I figure they know what they are doing; I&#8217;ll follow suit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sho</title>
		<link>http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/comment-page-1/#comment-293586</link>
		<dc:creator>Sho</dc:creator>
		<pubDate>Thu, 17 Sep 2009 23:55:34 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/#comment-293586</guid>
		<description>Hi Steven. Good point!

The issue is that in many languages (such as C++ or Java), (j+15)/7 *is* an integer operation when j is an int. So for those of us who come from those languages (and who see the strong typing in AS3 as a move toward those languages), this is confusing.

Even if you argue that having this be a floating point operation is &#039;better&#039; than having it be an integer operation, a modern compiler should be able to analyze the code to discover that the result of this operation is stored in an int and do an integer version of the division operation.

If I remember correctly, the player team investigated this approach, and found that it was difficult to get strictly correct behavior in edge cases (like dividing by NaN, etc). As a trade-off, they did an intrinsic conversion to Number in many cases that aren&#039;t strictly necessary.

They may have improved this in more recent version of the VM. I haven&#039;t worked at Adobe for 2 years, so I don&#039;t really know what&#039;s going on these days.</description>
		<content:encoded><![CDATA[<p>Hi Steven. Good point!</p>
<p>The issue is that in many languages (such as C++ or Java), (j+15)/7 *is* an integer operation when j is an int. So for those of us who come from those languages (and who see the strong typing in AS3 as a move toward those languages), this is confusing.</p>
<p>Even if you argue that having this be a floating point operation is &#8216;better&#8217; than having it be an integer operation, a modern compiler should be able to analyze the code to discover that the result of this operation is stored in an int and do an integer version of the division operation.</p>
<p>If I remember correctly, the player team investigated this approach, and found that it was difficult to get strictly correct behavior in edge cases (like dividing by NaN, etc). As a trade-off, they did an intrinsic conversion to Number in many cases that aren&#8217;t strictly necessary.</p>
<p>They may have improved this in more recent version of the VM. I haven&#8217;t worked at Adobe for 2 years, so I don&#8217;t really know what&#8217;s going on these days.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven</title>
		<link>http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/comment-page-1/#comment-293583</link>
		<dc:creator>Steven</dc:creator>
		<pubDate>Thu, 17 Sep 2009 23:36:18 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/#comment-293583</guid>
		<description>Sho, 

Your blanket statement that Number is better than int is not fair at all.

Your loop is doing an int() cast every single iteration.  Of course this is going to be slow.  Note the difference if you don&#039;t divide by 7 and it doesn&#039;t have to do a conversion.

var now:int = getTimer();
var j:int;
var i:int = 10000000;
while (i--)
{
    j = (j + 15);
}
trace(getTimer() - now);

41ms

If you divide by 7

154ms

Obviously, doing floating point math using Number is faster than doing it with int.  But doing integer math with int is MUCH faster than doing it with Number.

If you&#039;re using floats, use Number. If you&#039;re using integers, use int.</description>
		<content:encoded><![CDATA[<p>Sho, </p>
<p>Your blanket statement that Number is better than int is not fair at all.</p>
<p>Your loop is doing an int() cast every single iteration.  Of course this is going to be slow.  Note the difference if you don&#8217;t divide by 7 and it doesn&#8217;t have to do a conversion.</p>
<p>var now:int = getTimer();<br />
var j:int;<br />
var i:int = 10000000;<br />
while (i&#8211;)<br />
{<br />
    j = (j + 15);<br />
}<br />
trace(getTimer() &#8211; now);</p>
<p>41ms</p>
<p>If you divide by 7</p>
<p>154ms</p>
<p>Obviously, doing floating point math using Number is faster than doing it with int.  But doing integer math with int is MUCH faster than doing it with Number.</p>
<p>If you&#8217;re using floats, use Number. If you&#8217;re using integers, use int.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven</title>
		<link>http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/comment-page-1/#comment-293579</link>
		<dc:creator>Steven</dc:creator>
		<pubDate>Thu, 17 Sep 2009 21:42:06 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/#comment-293579</guid>
		<description>http://lab.polygonal.de/2007/06/06/int-uint-and-number-data-type-conversion/</description>
		<content:encoded><![CDATA[<p><a href="http://lab.polygonal.de/2007/06/06/int-uint-and-number-data-type-conversion/" rel="nofollow">http://lab.polygonal.de/2007/06/06/int-uint-and-number-data-type-conversion/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: [flash] Variables and Data types &#171; Not just a note</title>
		<link>http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/comment-page-1/#comment-293379</link>
		<dc:creator>[flash] Variables and Data types &#171; Not just a note</dc:creator>
		<pubDate>Mon, 14 Sep 2009 17:05:35 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/#comment-293379</guid>
		<description>[...] / Uint * Only works in whole numbers. &lt;Some said The Number works faster, see here, or [...]</description>
		<content:encoded><![CDATA[<p>[...] / Uint * Only works in whole numbers. &lt;Some said The Number works faster, see here, or [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Actionscript optimized types and why as3&#8217;s int sucks ass at tec.</title>
		<link>http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/comment-page-1/#comment-278346</link>
		<dc:creator>Actionscript optimized types and why as3&#8217;s int sucks ass at tec.</dc:creator>
		<pubDate>Wed, 06 May 2009 14:24:52 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/#comment-278346</guid>
		<description>[...] They writer of this blog actually suggests to default to Number instead of int, because Numbers are faster in most cases avoid ints in Actionscript [...]</description>
		<content:encoded><![CDATA[<p>[...] They writer of this blog actually suggests to default to Number instead of int, because Numbers are faster in most cases avoid ints in Actionscript [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The logical consequences that never happened at controul</title>
		<link>http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/comment-page-1/#comment-265148</link>
		<dc:creator>The logical consequences that never happened at controul</dc:creator>
		<pubDate>Sun, 22 Mar 2009 17:32:27 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/#comment-265148</guid>
		<description>[...] a BETTER one. Function inlining, mixing as3 and bytecode, optimised integer math (I do NOT want to work with Numbers); the list of possible enhancements was long. Why would anyone really need any of this? Mainly [...]</description>
		<content:encoded><![CDATA[<p>[...] a BETTER one. Function inlining, mixing as3 and bytecode, optimised integer math (I do NOT want to work with Numbers); the list of possible enhancements was long. Why would anyone really need any of this? Mainly [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sho</title>
		<link>http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/comment-page-1/#comment-257088</link>
		<dc:creator>Sho</dc:creator>
		<pubDate>Mon, 02 Mar 2009 18:24:04 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/#comment-257088</guid>
		<description>To Jacob and Drawtree:

Thanks for engaging in this discusssion!

Not sure what the timings are these days with player 10, but (a) you&#039;re right in the narrow sense, and (b) I still think there is an efficiency issue in the broader sense.

Jacob&#039;s point (and drawtree&#039;s, implicitly) is that certain operations are faster when done as ints. That is undoubtedly true.

However, for those of us who come from a non-dynamic language background (C / C++ / Java), the expectation is that built-in integral types are there precisely for the purposes of being faster than generic number types, even when doing things like printing them or dividing them.

In many other languages, dividing two integers compiles down to an integer division operation which is much much faster than a floating point integer division operation. In ActionScript (as of player 9, anyway), the integers are converted to number before the division. And as for the print statement specified in Gary&#039;s excellent talk, it&#039;s a mystery to me why the conversion occurs. Perhaps because the signature of the print method takes an untyped argument?

So... to summarize... I believe that the performance behavior of ints in ActionScript would be surprising to many people. Dividing two ints would normally be faster than dividing two floating point numbers, for example.

As for the title of the post, I may have been guilty of engaging in hyperbole. Maybe it should have been called &quot;consider using Number instead of int inside of tight loops&quot;. I certainly continue to use ints on a daily basis for typechecking purposes.</description>
		<content:encoded><![CDATA[<p>To Jacob and Drawtree:</p>
<p>Thanks for engaging in this discusssion!</p>
<p>Not sure what the timings are these days with player 10, but (a) you&#8217;re right in the narrow sense, and (b) I still think there is an efficiency issue in the broader sense.</p>
<p>Jacob&#8217;s point (and drawtree&#8217;s, implicitly) is that certain operations are faster when done as ints. That is undoubtedly true.</p>
<p>However, for those of us who come from a non-dynamic language background (C / C++ / Java), the expectation is that built-in integral types are there precisely for the purposes of being faster than generic number types, even when doing things like printing them or dividing them.</p>
<p>In many other languages, dividing two integers compiles down to an integer division operation which is much much faster than a floating point integer division operation. In ActionScript (as of player 9, anyway), the integers are converted to number before the division. And as for the print statement specified in Gary&#8217;s excellent talk, it&#8217;s a mystery to me why the conversion occurs. Perhaps because the signature of the print method takes an untyped argument?</p>
<p>So&#8230; to summarize&#8230; I believe that the performance behavior of ints in ActionScript would be surprising to many people. Dividing two ints would normally be faster than dividing two floating point numbers, for example.</p>
<p>As for the title of the post, I may have been guilty of engaging in hyperbole. Maybe it should have been called &#8220;consider using Number instead of int inside of tight loops&#8221;. I certainly continue to use ints on a daily basis for typechecking purposes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: drawtree</title>
		<link>http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/comment-page-1/#comment-257075</link>
		<dc:creator>drawtree</dc:creator>
		<pubDate>Mon, 02 Mar 2009 15:03:57 +0000</pubDate>
		<guid isPermaLink="false">http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/#comment-257075</guid>
		<description>The title and conclusion of this post is wrong. Jacob is right. Your code has serious logical bug, and it makes your conclusion wrong.

Refer 25p. of this document:
http://www.onflex.org/ACDS/AS3TuningInsideAVM2JIT.pdf

If you understand concept of explicit-type-casting you&#039;re already know what I want to say.</description>
		<content:encoded><![CDATA[<p>The title and conclusion of this post is wrong. Jacob is right. Your code has serious logical bug, and it makes your conclusion wrong.</p>
<p>Refer 25p. of this document:<br />
<a href="http://www.onflex.org/ACDS/AS3TuningInsideAVM2JIT.pdf" rel="nofollow">http://www.onflex.org/ACDS/AS3TuningInsideAVM2JIT.pdf</a></p>
<p>If you understand concept of explicit-type-casting you&#8217;re already know what I want to say.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

