Subj : Re: JSVAL_IS_NUMBER(NaN) == TRUE (!?) To : netscape.public.mozilla.jseng From : Justin Fletcher Date : Sun Feb 20 2005 04:08 pm On Sun, 20 Feb 2005, Rob Swindell wrote: > To: Brendan Eich > Re: Re: JSVAL_IS_NUMBER(NaN) == TRUE (!?) > By: Brendan Eich to Rob Swindell on Fri Feb 18 2005 02:55 pm > > > > I found it odd that if jsval is NaN, a test of JSVAL_IS_NUMBER(jsval) woul > > > evaluate as TRUE. > > > > > > Sure, it's of "number" type (see also typeof(0/0)). > > It just seemed illogical (to me) that: > > is (not a number) a number? > > would evaluate to a true statement. As Brendan just said - that's not the question that you're asking with that statement, though. JSVAL_IS_NUMBER(jsval) asks : is the intrinsic type of (jsval) a numeric type ? NaN is a numeric type value. JSVAL_IS_* is used at the lowest level for determining the type of data represented by a 'jsval'. It places no interpretation on the content of the data, if it is of that type. That there is particular representation within the type 'double' which indicates that the value is not a valid number is irrelevant to it. The documentation I have here (albeit a little dated) says this in a slightly more succinct manner : " Use JSVAL_IS_NUMBER to determine if a given JS value, v, is an integer or double value. If the type tag for v is JSVAL_INT or JSVAL_DOUBLE, JSVAL_IS_NUMBER evaluates to true. Otherwise, it evaluates to false. " -- Gerph .... This is a clown's tale; falling over again and again. .