Subj : Re: spidermonkey docu To : Jens Thiele From : Brendan Eich Date : Wed Apr 07 2004 02:44 pm Jens Thiele wrote: > the JS_ValueToInt32 docu is wrong: > http://mozilla.org/js/spidermonkey/apidoc/gen/complete.html#JS_ValueToInt32 > > Description > JS_ValueToInt32 converts a specified JS value, v, to a JS double, and > then to a 32-bit integer, if it fits. If the double is out of range, > JS_ValueToInt32 reports an error and conversion fails. The double > rounded to the nearest integer value. Agh, the doc is both too detailed (as if based on some misreading of code), and not complete (it doesn't define "out of range" fully). > > the corresponding source: > js_ValueToInt32(JSContext *cx, jsval v, int32 *ip) > { > jsdouble d; > JSString *str; > > if (JSVAL_IS_INT(v)) { > *ip = JSVAL_TO_INT(v); > return JS_TRUE; > } > [...] > > => js_ValueToInt32 does IMHO the right thing ;-) > if it is a JS int value convert to C int32 > if not try to convert it to an C int32 But the doc does not lie. Converting to double and then to int loses no information, it's just less efficient than what's actually done in the implementation. So I'm not sure why you say the doc is wrong. It is not in error, it's just (as usual, thanks to whoever wrote it for Netscape, ages ago) a bit misleading about implementation, a bit too detailed in that respect, and oddly not detailed enough in other ways. /be .