Inline js_DoubleToInteger (513436, r=sayrer).

This commit is contained in:
Andreas Gal 2009-08-29 02:36:45 -07:00
parent 7a4da2ecd3
commit 6424c04026
3 changed files with 21 additions and 23 deletions

View File

@ -1124,23 +1124,6 @@ js_ValueToUint16(JSContext *cx, jsval *vp)
return u;
}
jsdouble
js_DoubleToInteger(jsdouble d)
{
JSBool neg;
if (d == 0)
return d;
if (!JSDOUBLE_IS_FINITE(d)) {
if (JSDOUBLE_IS_NaN(d))
return 0;
return d;
}
neg = (d < 0);
d = floor(neg ? -d : d);
return neg ? -d : d;
}
JSBool
js_strtod(JSContext *cx, const jschar *s, const jschar *send,
const jschar **ep, jsdouble *dp)

View File

@ -368,8 +368,23 @@ js_ValueToUint16(JSContext *cx, jsval *vp);
* Convert a jsdouble to an integral number, stored in a jsdouble.
* If d is NaN, return 0. If d is an infinity, return it without conversion.
*/
extern jsdouble
js_DoubleToInteger(jsdouble d);
static inline jsdouble
js_DoubleToInteger(jsdouble d)
{
if (d == 0)
return d;
if (!JSDOUBLE_IS_FINITE(d)) {
if (JSDOUBLE_IS_NaN(d))
return 0;
return d;
}
JSBool neg = (d < 0);
d = floor(neg ? -d : d);
return neg ? -d : d;
}
/*
* Similar to strtod except that it replaces overflows with infinities of the

View File

@ -523,12 +523,12 @@ static inline bool
JS_ISSPACE(jschar c)
{
uint32 w = uint32(c);
if (w < 256) {
if (w < 256)
return w <= ' ' && (w == ' ' || (9 <= w && w <= 0xD));
} else {
return (JS_CCODE(w) & 0x00070000) == 0x00040000;
}
}
#define JS_ISPRINT(c) ((c) < 128 && isprint(c))