[BUG] `math.gcd(Int.MIN, n)` never returns
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- backend
Hướng nghiên cứu
Lỗi treo nằm ở hàm gcd với số nguyên trong Mojo/stdlib/std/math/math.mojo, khoảng dòng 2634-2652, nơi độ lớn được tính bằng abs rồi rút gọn trong vòng lặp dịch bit và trừ. Chạy đoạn tái hiện ba dòng trong issue với timeout để xác nhận gcd(Int.MIN, 6) không bao giờ trả về. Hoàn thành khi hàm trả về 2, các trường hợp MIN khác khớp với issue, và một maintainer trả lời câu hỏi còn mở về việc gcd(Int.MIN, 0) có trả về 2^63 hay không.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Mojo
- Star
- 30.2k
- Fork
- 3.2k
- Merge trung bình
- 6 ngày 20 giờ
- Pull request đã merge (30 ngày)
- 25
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modular/modular
-
[BUG]Incomplete Apache LicenseĐang mởbug bug_feature_triaged documentation mojo
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 2 ngày
-
`Counter.lt()` and `Counter.gt()` disagree with `__eq__`, and `a.lt(a)` can be `True`Có thể đã có người làm @YidaWeng đã nhận 1 ngày trước. Đang mởbug_feature_triaged Team: Mojo Libraries
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
modular/modular#7696 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[BUG] `Counter` `-=`, `+=` and `&=` leave keys behind when they remove many keysCó thể đã có người làm @Tharun-Kumar-McW đã nhận 4 ngày trước. Đang mởbug bug_feature_triaged mojo-stdlib Team: Mojo Libraries
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
modular/modular#7658 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[BUG] exp(NaN) returns infĐang mởbug bug_feature_triaged mojo Team: Mojo Libraries
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
modular/modular#7646 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Feature Request] Implement `os.getcwd`Có thể đã có người làm @shubhxho đã nhận 16 ngày trước. Đang mởbug_feature_triaged Team: Mojo Libraries
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của modular/modular
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
letsrevel/revel-backend#1520 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
backend enhancement good first issue help wanted
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
nikhilb2/simple_invoicing#931 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
diivi/aseprite-mcp#43 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
NCAR/MMM-physics#33 ·
-
[Fix] sse: Drop the complete remainder of oversized physical linesCó thể đã có người làm @he-yufeng đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
sgl-project/sglang#52408 ·
Maintainer thường phản hồi trong vòng 1 ngày