Wrong result when comparing a negative BigInt with a negative float
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず QuickJS のソースコードで js_bigint_float64_cmp を読み、指数の比較と既存の仮数分岐に注目します。issue にある BigInt と float の負の値同士の比較を 4 つ再現し、その後、すべての関係演算子を確認します。これらのケースが Node と仕様に一致すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Comparing a negative BigInt with a negative float gives the wrong answer when their binary exponents differ.
Tested on master (19d6bd8):
console.log(-0.5 < -1n); // true, expected false
console.log(-1n > -0.5); // true, expected false
console.log(-2147483648 < -1n); // false, expected true
console.log(-1n < -2147483648); // true, expected false
Node and the spec give the expected values. All relational operators are affected.
In js_bigint_float64_cmp, when both numbers have the same sign and their exponents differ, the result is -1 for f < e whatever the sign. For two negative numbers the one with the smaller exponent is the larger number. The mantissa branch just below already takes the sign into account. A fix that makes all four cases above match Node:
@@ static int js_bigint_float64_cmp(JSContext *ctx, const JSBigInt *a,
a_mant = js_bigint_get_mant_exp(ctx, &f, a);
if (f != e) {
if (f < e)
- return -1;
+ return 2 * a_sign - 1;
else
- return 1;
+ return 1 - 2 * a_sign;
} else {
- 主要言語
- C
- スター
- 11.1k
- フォーク
- 1.2k
- 平均マージ
- 11時間 20分
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
bellard/quickjs のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
メンテナーはふだん 3 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
メンテナーはふだん 3 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 3 日以内に返信
-
Collecting WeakMap keys requires multiple GC passes対応中かも @jluxenberg が 1 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
bellard/quickjs#581 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
メンテナーはふだん 3 日以内に返信
bellard/quickjs の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
InukaAsith/TwinDesk#84 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
CanadaHonk/porffor#426 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 77/100
raysan5/raylib.com#132 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100