In as, we use the is operator to determine the data type.
But what are the results of the uint, Int, and number values?
Let's do a small test:
VaR U: uint = 3; <br/> trace (U is uint); // true <br/> trace (U is int ); // true <br/> trace (U is number); // true </P> <p> var I: Int = 4; <br/> trace (I is uint); // true <br/> trace (I is int); // true <br/> trace (I is number ); // true </P> <p> var N: Number = 5; <br/> trace (N is uint ); // true <br/> trace (N is int); // true <br/> trace (N is number ); // true </P> <p> var number: Number = 6.6; <br/> trace (number is uint ); // false <br/> trace (number is int); // false <br/> trace (number is number); // true <br/>
It can be seen that the is operator does not strictly judge the data of the three data types according to the originally defined data types, and is true if it is convertible.
We use the isnan () function to check whether a mathematical expression is successfully calculated as a number. If the value isNaN
(Not a number), returntrue。
The Nan value is a special member of the number data type, but is not a member of the Int or uint data type. It is used to represent a "non-number" value.
By the way, we will introduce two as top-level constants-infinity and infinity, which are easily overlooked:
-Infinity: NegativeInfinity
. The value of this constant correspondsNumber.NEGATIVE_INFINITY
Same.
Infinity: positiveInfinity
. The value of this constant correspondsNumber.POSITIVE_INFINITY
Same.
trace(0 / 0); // NaN<br />trace(7 / 0); // Infinity<br />trace(-7 / 0); // -Infinity<br />
Next, we will continue a set of tests:
var n:Number = 6.6;<br />trace(!isNaN(n)); //true<br />trace(!isNaN(n) && n != Infinity && n != -Infinity) //true<br />var nn:Number = 6.6 / 0;<br />trace(nn); //Infinity<br />trace(!isNaN(nn)); //true<br />trace(!isNaN(nn) && nn != Infinity && nn != -Infinity) //false<br />var nan:Number = 0 / 0;<br />trace(nan); //NaN<br />trace(nan is Number); //true<br />trace(!isNaN(nan)); //false
It can be seen that we cannot simply use the is number when checking whether a variable is a valid number, but use the isnan () function.
When! Isnan (value) returns true and is not equal to +/-infinity, which indicates that it is a valid number value.