[BUG] `math.gcd(Int.MIN, n)` never returns
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 72/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 領域
- backend
調査の方向性
ハングは Mojo/stdlib/std/math/math.mojo の整数 gcd にあり、2634〜2652行目付近で、絶対値を abs で計算したあと、シフトと減算のループで縮小しています。issue の3行の再現コードを timeout 付きで実行し、gcd(Int.MIN, 6) が戻らないことを確認してください。2 を返し、他の MIN のケースが issue どおりになり、gcd(Int.MIN, 0) が 2^63 を返すかどうかという未解決の質問にメンテナーが回答すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Bug description
Tiny one I hit while writing down std.math's contracts in Lean for MojoProof: gcd(Int.MIN, 6) never returns. It should be 2. gcd(6, Int.MIN) and the Span and variadic overloads hang too, and inputs right next to MIN are fine. (AI helped me find the loop below; I checked it.)
Actual behavior
It hangs.
Expected behavior
Steps to reproduce
from std.benchmark import black_box
from std.math import gcd
def main():
print(gcd(black_box(Int.MIN + 2), 4), flush=True) # 2
print(gcd(black_box(Int.MIN), 0), flush=True) # Int.MIN (2**63 does not fit)
print(gcd(black_box(Int.MIN), 6)) # never returns, expected 2
$ timeout 20 mojo run repro.mojo; echo "exit=$?"
2
-9223372036854775808
exit=124
abs(Int.MIN) is still Int.MIN, so u starts out negative (math.mojo#L2634), and the shift and min(u, v) in the loop keep it negative, so diff never reaches 0 (L2645-L2652). Taking the magnitudes as UInt and running the same binary GCD fixes it: a copy written that way gives 2, 4 and 2 for gcd(Int.MIN, 6), gcd(Int.MIN, 4) and gcd(6, Int.MIN).
One question: gcd(Int.MIN, 0) and gcd(Int.MIN, Int.MIN) are 2^63, which doesn't fit in Int (today the first returns Int.MIN). Would you rather abort there, or keep the wrapped value and document it? I'm happy to open a PR with the UInt version :)
System information
Mojo 1.3.0.dev2026112105 (f23ed0af), MAX 26.8.0.dev2026112105, installed with pip from the nightly index. Amazon Linux 2023, x86_64, Intel Xeon Platinum 8275CL.
- 主要言語
- Mojo
- スター
- 30.2k
- フォーク
- 3.2k
- 平均マージ
- 6日 20時間
- マージ済み PR(30日)
- 25
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modular/modular のほかの issue
-
bug bug_feature_triaged documentation mojo
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
メンテナーはふだん 2 日以内に返信
-
`Counter.lt()` and `Counter.gt()` disagree with `__eq__`, and `a.lt(a)` can be `True`対応中かも @YidaWeng が 1 日前に担当しました。 オープンbug_feature_triaged Team: Mojo Libraries
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
modular/modular#7696 · コメント 2 件 ·
メンテナーはふだん 2 日以内に返信
-
[BUG] `Counter` `-=`, `+=` and `&=` leave keys behind when they remove many keys対応中かも @Tharun-Kumar-McW が 4 日前に担当しました。 オープンbug bug_feature_triaged mojo-stdlib Team: Mojo Libraries
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
modular/modular#7658 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
bug bug_feature_triaged mojo Team: Mojo Libraries
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
modular/modular#7646 · コメント 3 件 ·
メンテナーはふだん 2 日以内に返信
-
[Feature Request] Implement `os.getcwd`対応中かも @shubhxho が 16 日前に担当しました。 オープンbug_feature_triaged Team: Mojo Libraries
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 2 日以内に返信
modular/modular の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
letsrevel/revel-backend#1520 ·
メンテナーはふだん 1 日以内に返信
-
backend enhancement good first issue help wanted
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
nikhilb2/simple_invoicing#931 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
diivi/aseprite-mcp#43 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
NCAR/MMM-physics#33 ·
-
[Fix] sse: Drop the complete remainder of oversized physical lines対応中かも @he-yufeng が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
sgl-project/sglang#52408 ·
メンテナーはふだん 1 日以内に返信