]> git.kaiwu.me - quickjs.git/commitdiff
avoid using INT64_MAX in double comparisons because it cannot be exactly represented...
authorFabrice Bellard <fabrice@bellard.org>
Sat, 3 Feb 2024 14:48:57 +0000 (15:48 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Sat, 3 Feb 2024 14:48:57 +0000 (15:48 +0100)
quickjs.c

index 5923a870ff395f75badfd9fdd4fb1dd0115057ea..7958f81f7115c64fb5431cb1a593284b5b58ccf2 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -10771,7 +10771,7 @@ static int JS_ToInt64SatFree(JSContext *ctx, int64_t *pres, JSValue val)
             } else {
                 if (d < INT64_MIN)
                     *pres = INT64_MIN;
-                else if (d > INT64_MAX)
+                else if (d >= 0x1p63) /* must use INT64_MAX + 1 because INT64_MAX cannot be exactly represented as a double */
                     *pres = INT64_MAX;
                 else
                     *pres = (int64_t)d;
@@ -55350,7 +55350,8 @@ static JSValue js_atomics_wait(JSContext *ctx,
     }
     if (JS_ToFloat64(ctx, &d, argv[3]))
         return JS_EXCEPTION;
-    if (isnan(d) || d > INT64_MAX)
+    /* must use INT64_MAX + 1 because INT64_MAX cannot be exactly represented as a double */
+    if (isnan(d) || d >= 0x1p63)
         timeout = INT64_MAX;
     else if (d < 0)
         timeout = 0;