Fix of Infinity handling
This commit is contained in:
parent
e682f63cd0
commit
95e55eb1cb
2 changed files with 19 additions and 5 deletions
|
@ -47540,7 +47540,7 @@ static const JSCFunctionListEntry js_global_funcs[] = {
|
||||||
JS_CFUNC_MAGIC_DEF("encodeURIComponent", 1, js_global_encodeURI, 1 ),
|
JS_CFUNC_MAGIC_DEF("encodeURIComponent", 1, js_global_encodeURI, 1 ),
|
||||||
JS_CFUNC_DEF("escape", 1, js_global_escape ),
|
JS_CFUNC_DEF("escape", 1, js_global_escape ),
|
||||||
JS_CFUNC_DEF("unescape", 1, js_global_unescape ),
|
JS_CFUNC_DEF("unescape", 1, js_global_unescape ),
|
||||||
JS_PROP_DOUBLE_DEF("Infinity", 1.0 / 0.0, 0 ),
|
JS_PROP_DOUBLE_DEF("Infinity", INFINITY, 0 ),
|
||||||
JS_PROP_DOUBLE_DEF("NaN", NAN, 0 ),
|
JS_PROP_DOUBLE_DEF("NaN", NAN, 0 ),
|
||||||
JS_PROP_UNDEFINED_DEF("undefined", 0 ),
|
JS_PROP_UNDEFINED_DEF("undefined", 0 ),
|
||||||
|
|
||||||
|
|
22
quickjs.h
22
quickjs.h
|
@ -132,16 +132,24 @@ typedef struct JSRefCountHeader {
|
||||||
#define JS_MKVAL(tag, val) (((uint64_t)(0xF & tag) << 48) | (uint32_t)(val))
|
#define JS_MKVAL(tag, val) (((uint64_t)(0xF & tag) << 48) | (uint32_t)(val))
|
||||||
#define JS_MKPTR(tag, ptr) (((uint64_t)(0xF & tag) << 48) | ((uint64_t)(ptr) & 0x0000FFFFFFFFFFFFull))
|
#define JS_MKPTR(tag, ptr) (((uint64_t)(0xF & tag) << 48) | ((uint64_t)(ptr) & 0x0000FFFFFFFFFFFFull))
|
||||||
|
|
||||||
#define JS_NAN JS_MKVAL(JS_TAG_FLOAT64,1)
|
#define JS_NAN JS_MKVAL(JS_TAG_FLOAT64,0)
|
||||||
|
#define JS_INFINITY_NEGATIVE JS_MKVAL(JS_TAG_FLOAT64,1)
|
||||||
|
#define JS_INFINITY_POSITIVE JS_MKVAL(JS_TAG_FLOAT64,2)
|
||||||
|
|
||||||
static inline double JS_VALUE_GET_FLOAT64(JSValue v)
|
static inline double JS_VALUE_GET_FLOAT64(JSValue v)
|
||||||
{
|
{
|
||||||
|
if (v > 0xFFFFFFFFFFFFFull) {
|
||||||
union { JSValue v; double d; } u;
|
union { JSValue v; double d; } u;
|
||||||
if (v == JS_NAN)
|
|
||||||
return JS_FLOAT64_NAN;
|
|
||||||
u.v = ~v;
|
u.v = ~v;
|
||||||
return u.d;
|
return u.d;
|
||||||
}
|
}
|
||||||
|
else if (v == JS_NAN)
|
||||||
|
return JS_FLOAT64_NAN;
|
||||||
|
else if (v == JS_INFINITY_POSITIVE)
|
||||||
|
return INFINITY;
|
||||||
|
else
|
||||||
|
return -INFINITY;
|
||||||
|
}
|
||||||
|
|
||||||
static inline JSValue __JS_NewFloat64(JSContext *ctx, double d)
|
static inline JSValue __JS_NewFloat64(JSContext *ctx, double d)
|
||||||
{
|
{
|
||||||
|
@ -149,8 +157,14 @@ typedef struct JSRefCountHeader {
|
||||||
JSValue v;
|
JSValue v;
|
||||||
u.d = d;
|
u.d = d;
|
||||||
/* normalize NaN */
|
/* normalize NaN */
|
||||||
if (js_unlikely((u.u64 & 0x7ff0000000000000) == 0x7ff0000000000000))
|
if (js_unlikely((u.u64 & 0x7ff0000000000000) == 0x7ff0000000000000)) {
|
||||||
|
if( isnan(d))
|
||||||
v = JS_NAN;
|
v = JS_NAN;
|
||||||
|
else if (d < 0.0)
|
||||||
|
v = JS_INFINITY_NEGATIVE;
|
||||||
|
else
|
||||||
|
v = JS_INFINITY_POSITIVE;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
v = ~u.u64;
|
v = ~u.u64;
|
||||||
return v;
|
return v;
|
||||||
|
|
Loading…
Reference in a new issue