<?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: Are AS3 Number Variables Real Objects or Not?</title>
	<atom:link href="http://www.techper.net/2008/09/11/are-as3-number-variables-real-objects-or-not/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techper.net/2008/09/11/are-as3-number-variables-real-objects-or-not/</link>
	<description>About Technology in My Life</description>
	<lastBuildDate>Thu, 11 Mar 2010 05:52:37 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Tom</title>
		<link>http://www.techper.net/2008/09/11/are-as3-number-variables-real-objects-or-not/comment-page-1/#comment-11186</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Tue, 03 Mar 2009 16:43:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=133#comment-11186</guid>
		<description>I was trying to use a Number in a constructor and have it as an optional parameter, and if it was not specified I wanted it to match the value of one of the other, required, parameters. Since my class could use both positive, negative, and zero as valid values I couldn&#039;t think of a way to accomplish this since Number can&#039;t be set to null.

I wanted to do:

public function SomeClass(minVal:Number,maxVal:Number,defaultVal:Number=null) {
if (defaultVal==null) {defaultVal=minVal;}

The workaround is to default the parameter to &quot;Infinity&quot; and check against that since Infinity could never be a valid value for my class:

public function SomeClass(minVal:Number,maxVal:Number,defaultVal:Number=Infinity) {
if (!isFinite(defaultVal)) {defaultVal=minVal;}</description>
		<content:encoded><![CDATA[<p>I was trying to use a Number in a constructor and have it as an optional parameter, and if it was not specified I wanted it to match the value of one of the other, required, parameters. Since my class could use both positive, negative, and zero as valid values I couldn&#8217;t think of a way to accomplish this since Number can&#8217;t be set to null.</p>
<p>I wanted to do:</p>
<p>public function SomeClass(minVal:Number,maxVal:Number,defaultVal:Number=null) {<br />
if (defaultVal==null) {defaultVal=minVal;}</p>
<p>The workaround is to default the parameter to &#8220;Infinity&#8221; and check against that since Infinity could never be a valid value for my class:</p>
<p>public function SomeClass(minVal:Number,maxVal:Number,defaultVal:Number=Infinity) {<br />
if (!isFinite(defaultVal)) {defaultVal=minVal;}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Link Post Sunday 09/14 &#124; Mr Sun Studios</title>
		<link>http://www.techper.net/2008/09/11/are-as3-number-variables-real-objects-or-not/comment-page-1/#comment-2910</link>
		<dc:creator>Link Post Sunday 09/14 &#124; Mr Sun Studios</dc:creator>
		<pubDate>Sun, 21 Sep 2008 17:47:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=133#comment-2910</guid>
		<description>[...] and Flex APIs Lack in Quality and Are AS3 Number Variables Objects or Not? by Tech [...]</description>
		<content:encoded><![CDATA[<p>[...] and Flex APIs Lack in Quality and Are AS3 Number Variables Objects or Not? by Tech [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danny Miller</title>
		<link>http://www.techper.net/2008/09/11/are-as3-number-variables-real-objects-or-not/comment-page-1/#comment-2762</link>
		<dc:creator>Danny Miller</dc:creator>
		<pubDate>Wed, 17 Sep 2008 04:56:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=133#comment-2762</guid>
		<description>Great question regarding data types. I actually just wrote a post on my wordpress to answer
http://k2xl.com/wordpress/2008/09/17/as3-primitives/</description>
		<content:encoded><![CDATA[<p>Great question regarding data types. I actually just wrote a post on my wordpress to answer<br />
<a href="http://k2xl.com/wordpress/2008/09/17/as3-primitives/" rel="nofollow">http://k2xl.com/wordpress/2008/09/17/as3-primitives/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Theo</title>
		<link>http://www.techper.net/2008/09/11/are-as3-number-variables-real-objects-or-not/comment-page-1/#comment-2675</link>
		<dc:creator>Theo</dc:creator>
		<pubDate>Fri, 12 Sep 2008 06:49:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=133#comment-2675</guid>
		<description>5 is Object // =&gt; true

new int(4) // =&gt; 4

5.5.toString() // =&gt; &quot;5.5&quot;

These statements should be quite conclusive, instances of Number are instances of Object. That doesn&#039;t mean that variables typed as Number, int, uint and Boolean work like variables typed as Object, for example you can&#039;t null them.

But there&#039;s a difference here, &quot;myNumber is Object&quot; tests the &lt;em&gt;value&lt;/em&gt; of the &quot;myNumber&quot; variable, whereas &quot;myNumber = null&quot; sets the &lt;em&gt;variable&lt;/em&gt; to null. So Number objects are objects, but variables typed Number are not like other variables, but subject to compiler and runtime optimizations.

---

Another weird detail, if you want to call a method on a number literal you can&#039;t do

5.toString()

because the &quot;.&quot; is considered to be the decimal point, however

5..toString() 

works fine (because &quot;5.&quot; is the same as &quot;5.0&quot;).

http://blog.iconara.net/2007/03/16/architectural-atrocities-part-7-some-types-are-less-equal-than-others/</description>
		<content:encoded><![CDATA[<p>5 is Object // =&gt; true</p>
<p>new int(4) // =&gt; 4</p>
<p>5.5.toString() // =&gt; &#8220;5.5&#8243;</p>
<p>These statements should be quite conclusive, instances of Number are instances of Object. That doesn&#8217;t mean that variables typed as Number, int, uint and Boolean work like variables typed as Object, for example you can&#8217;t null them.</p>
<p>But there&#8217;s a difference here, &#8220;myNumber is Object&#8221; tests the <em>value</em> of the &#8220;myNumber&#8221; variable, whereas &#8220;myNumber = null&#8221; sets the <em>variable</em> to null. So Number objects are objects, but variables typed Number are not like other variables, but subject to compiler and runtime optimizations.</p>
<p>&#8212;</p>
<p>Another weird detail, if you want to call a method on a number literal you can&#8217;t do</p>
<p>5.toString()</p>
<p>because the &#8220;.&#8221; is considered to be the decimal point, however</p>
<p>5..toString() </p>
<p>works fine (because &#8220;5.&#8221; is the same as &#8220;5.0&#8243;).</p>
<p><a href="http://blog.iconara.net/2007/03/16/architectural-atrocities-part-7-some-types-are-less-equal-than-others/" rel="nofollow">http://blog.iconara.net/2007/03/16/architectural-atrocities-part-7-some-types-are-less-equal-than-others/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darren</title>
		<link>http://www.techper.net/2008/09/11/are-as3-number-variables-real-objects-or-not/comment-page-1/#comment-2674</link>
		<dc:creator>Darren</dc:creator>
		<pubDate>Fri, 12 Sep 2008 05:32:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=133#comment-2674</guid>
		<description>The way I see it, if the compiler had given you an error instead of a warning when you incorrectly tried to assign null to a special type of object that is non-nullable then you wouldn&#039;t have written this post. For whatever reason, the compiler seems to have silently cast null to Number (0). Maybe this is a deliberate design decision to handle some border cases, hence the warning to make sure that you really did intend to do it? If you get a warning and then choose to ignore it, then you can hardly complain about unexpected results, no?</description>
		<content:encoded><![CDATA[<p>The way I see it, if the compiler had given you an error instead of a warning when you incorrectly tried to assign null to a special type of object that is non-nullable then you wouldn&#8217;t have written this post. For whatever reason, the compiler seems to have silently cast null to Number (0). Maybe this is a deliberate design decision to handle some border cases, hence the warning to make sure that you really did intend to do it? If you get a warning and then choose to ignore it, then you can hardly complain about unexpected results, no?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shaun</title>
		<link>http://www.techper.net/2008/09/11/are-as3-number-variables-real-objects-or-not/comment-page-1/#comment-2668</link>
		<dc:creator>shaun</dc:creator>
		<pubDate>Fri, 12 Sep 2008 01:02:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=133#comment-2668</guid>
		<description>Hi,
   1. var foo : Number = null;  
   2. trace(&quot;foo=&quot;+foo);  
Establishes foo is really 0 (with a warning).

&quot;You might be alarmed to hear then, that isNaN() applied on a Number typed variable, which have previously been assigned null, will return false.&quot;

1. var foo : Number = null;   //So this is really 0, established prior.
2. trace(&quot;foo=&quot;+foo);         //prints 0
3. isNaN(foo) == false, is correct. // foo is 0, which is a Number.
The result of isNaN seems reasonable to me.

However i do see your point about the Number class itself and not being able to test for null. However as you can see above - the Number is never null
but rather 0.
I think that probably the compiler should generate an error when you assign null to a type Number rather than just a warning, which would then make it consistent with the conditional testing against null.

Nice post.</description>
		<content:encoded><![CDATA[<p>Hi,<br />
   1. var foo : Number = null;<br />
   2. trace(&#8221;foo=&#8221;+foo);<br />
Establishes foo is really 0 (with a warning).</p>
<p>&#8220;You might be alarmed to hear then, that isNaN() applied on a Number typed variable, which have previously been assigned null, will return false.&#8221;</p>
<p>1. var foo : Number = null;   //So this is really 0, established prior.<br />
2. trace(&#8221;foo=&#8221;+foo);         //prints 0<br />
3. isNaN(foo) == false, is correct. // foo is 0, which is a Number.<br />
The result of isNaN seems reasonable to me.</p>
<p>However i do see your point about the Number class itself and not being able to test for null. However as you can see above &#8211; the Number is never null<br />
but rather 0.<br />
I think that probably the compiler should generate an error when you assign null to a type Number rather than just a warning, which would then make it consistent with the conditional testing against null.</p>
<p>Nice post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith Peters</title>
		<link>http://www.techper.net/2008/09/11/are-as3-number-variables-real-objects-or-not/comment-page-1/#comment-2665</link>
		<dc:creator>Keith Peters</dc:creator>
		<pubDate>Thu, 11 Sep 2008 23:07:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=133#comment-2665</guid>
		<description>this might help:

http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00000048.html</description>
		<content:encoded><![CDATA[<p>this might help:</p>
<p><a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00000048.html" rel="nofollow">http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00000048.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Tynjala</title>
		<link>http://www.techper.net/2008/09/11/are-as3-number-variables-real-objects-or-not/comment-page-1/#comment-2661</link>
		<dc:creator>Josh Tynjala</dc:creator>
		<pubDate>Thu, 11 Sep 2008 21:48:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=133#comment-2661</guid>
		<description>Number, int, uint, Boolean, and String are special types. They don&#039;t act like normal Objects. Most importantly, they aren&#039;t nullable. Additionally, they are compared by value rather than by reference.

var a:Object = {};
var b:Object = {}

a == b //false

var c:Number = 1;
var d:Number = 1;

c == d //true

Additionally, it&#039;s important to know that null, undefined, and 0 may all go through type conversions when you do comparisons or assignment.

//EXAMPLE 1
var nullNum:Number = null;
trace(nullNum) //0

It is 0 because null gets type converted to work as a Number. That&#039;s why isNaN() fails.


//EXAMPLE 2
var zero:Number = 0;
if(!zero)
{
   trace(&quot;zero got type converted&quot;);
}

This can be tricky when you actually want a nullable value. For instance, the following code works:

var styles:Object = {color: 0xff0000, alpha: 0.5};
if(styles.color)
{
   //if color is defined, do something
}

...but what happens when you change the value of &quot;color&quot; to black?

var styles:Object = {color: 0x000000, alpha: 0.5};
if(styles.color)
{
   //the code in this if statement won&#039;t run
}

Color is now equal to zero, which is type converted and becomes false in the comparison.

In short, you&#039;ve discovered a very tricky part of the core types. It is defined as part of the ECMAScript specification, so this stuff is documented somewhere. I&#039;m not sure if Adobe points it out anywhere, though.</description>
		<content:encoded><![CDATA[<p>Number, int, uint, Boolean, and String are special types. They don&#8217;t act like normal Objects. Most importantly, they aren&#8217;t nullable. Additionally, they are compared by value rather than by reference.</p>
<p>var a:Object = {};<br />
var b:Object = {}</p>
<p>a == b //false</p>
<p>var c:Number = 1;<br />
var d:Number = 1;</p>
<p>c == d //true</p>
<p>Additionally, it&#8217;s important to know that null, undefined, and 0 may all go through type conversions when you do comparisons or assignment.</p>
<p>//EXAMPLE 1<br />
var nullNum:Number = null;<br />
trace(nullNum) //0</p>
<p>It is 0 because null gets type converted to work as a Number. That&#8217;s why isNaN() fails.</p>
<p>//EXAMPLE 2<br />
var zero:Number = 0;<br />
if(!zero)<br />
{<br />
   trace(&#8221;zero got type converted&#8221;);<br />
}</p>
<p>This can be tricky when you actually want a nullable value. For instance, the following code works:</p>
<p>var styles:Object = {color: 0xff0000, alpha: 0.5};<br />
if(styles.color)<br />
{<br />
   //if color is defined, do something<br />
}</p>
<p>&#8230;but what happens when you change the value of &#8220;color&#8221; to black?</p>
<p>var styles:Object = {color: 0&#215;000000, alpha: 0.5};<br />
if(styles.color)<br />
{<br />
   //the code in this if statement won&#8217;t run<br />
}</p>
<p>Color is now equal to zero, which is type converted and becomes false in the comparison.</p>
<p>In short, you&#8217;ve discovered a very tricky part of the core types. It is defined as part of the ECMAScript specification, so this stuff is documented somewhere. I&#8217;m not sure if Adobe points it out anywhere, though.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
