Subj : JSVAL_IS_NUMBER(NaN) == TRUE (!?) To : All From : Rob Swindell Date : Fri Feb 18 2005 03:21 am SpiderMonkey oddity: I found it odd that if jsval is NaN, a test of JSVAL_IS_NUMBER(jsval) would evaluate as TRUE. And my native methods don't consider NaN a valid number either, so I needed a valid test for is number, but non NaN, so I came up with: #include /* JSDOUBLE_IS_NaN() */ JSBool jsval_isNaN(JSContext *cx, jsval v) { jsdouble d; if(JSVAL_IS_DOUBLE(v)) { if (!JS_ValueToNumber(cx, v, &d)) return JS_FALSE; if(JSDOUBLE_IS_NaN(d)) return JS_TRUE; } return JS_FALSE; } // Replacement for JSVAL_IS_NUMBER(): #define JSVAL_IS_NUM(cx,v) (JSVAL_IS_NUMBER(v) && !jsval_isNaN(cx,v)) I'm surprised there's not something like this already in the jsapi. digital man Snapple "Real Fact" #114: The oldest known animal was a tortoise, which lived to be 152 years old. .