Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Wrong result when comparing a negative BigInt with a negative float

オープン 初心者向け
#583 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c
領域
backend

調査の方向性

まず 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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bellard/quickjs のほかの issue

bellard/quickjs の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。