cmath.log(0, base) returns (-inf+nanj) instead of raising ValueError

Đang mở
#161,972 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, python
Lĩnh vực
backend

Hướng nghiên cứu

Start at cmath_log_impl, where the issue says c_log(z)'s domain error is lost when c_log(base) resets errno. Read the existing tests for cmath.log and run the focused cmath tests. Done means cmath.log(0, base) raises ValueError: math domain error while existing base-related behavior remains covered.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Bug report

cmath.log(0) raises ValueError, but cmath.log(0, base) returns a value such as (-inf+nanj) for most bases. In cmath_log_impl, the domain error from c_log(z) is stored in errno, and the second call c_log(base) resets errno to 0 before it is checked.

import cmath, math

cmath.log(0)       # ValueError: math domain error
cmath.log(0, 2)    # (-inf+nanj)
cmath.log(0, -1)   # (nan+infj)
math.log(0, 2)     # ValueError: expected a positive input

Expected: cmath.log(0, base) raises ValueError: math domain error, the same as cmath.log(0) and math.log(0, 2). A zero or one base already raises (cmath.log(2, 0), cmath.log(2, 1)), because there the error comes from the second call or from the division.

CPython versions tested on:

3.15, CPython main branch

Operating systems tested on:

Linux


Found while building a Lean 4 model of CPython (https://broyojo.com/python-formalization/). AI tools (Claude) helped investigate the findings and prepare this report. The examples were rerun on CPython 3.15.2 and main, and the report received technical review. Record: mathint-cmath-log-base-errno

Ngôn ngữ chính
Python
Star
78.2k
Fork
36.6k
Merge trung bình
19 giờ 57 phút
Pull request đã merge (30 ngày)
630

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/cpython

Tất cả issue của python/cpython

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.