ValueError for `math.atan2(0.0, 0.0)` and `cmath.phase(0.0)` using icx
未关闭
还没有人认领这个 Issue。
extension-modules
OS-unsupported
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
The math function atan2 and the cmath function phase should not raise ValueError when their arguments are zero. This is true when building CPython using an officially supported compiler such as GCC:
>>> import math
>>> import cmath
>>> math.atan2(0.0, 0.0)
0.0
>>> cmath.phase(complex(0.0, 0.0))
0.0
>>> math.atan2(0.0, -0.0)
3.141592653589793
>>> cmath.phase(complex(-0.0, 0.0))
3.141592653589793
However, The C23 standard (ISO/IEC 9899:2024) in section 7.12.4.4 for atan2 states:
A domain error may occur if both arguments are zero.
The Intel math library version 2026.0.0 sets errno to EDOM for these cases. See also PR #152825. Thus:
>>> import math
>>> import cmath
>>> math.atan2(0.0, 0.0)
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
math.atan2(0.0, 0.0)
~~~~~~~~~~^^^^^^^^^^
ValueError: math domain error
>>> cmath.phase(complex(0.0, 0.0))
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
cmath.phase(complex(0.0, 0.0))
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
ValueError: math domain error
>>> math.atan2(0.0, -0.0)
Traceback (most recent call last):
File "<python-input-4>", line 1, in <module>
math.atan2(0.0, -0.0)
~~~~~~~~~~^^^^^^^^^^^
ValueError: math domain error
>>> cmath.phase(complex(-0.0, 0.0))
Traceback (most recent call last):
File "<python-input-5>", line 1, in <module>
cmath.phase(complex(-0.0, 0.0))
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
ValueError: math domain error
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-153148
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先检查 PR #152825 和关联的 PR #153148,因为它们似乎在处理此报告。首先跟踪 math.atan2 和 cmath.phase 的 CPython 实现,并比较 icx 与 GCC 下的行为。当零值参数不再引发 ValueError,并保留文档中说明的 signed-zero 结果时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 20/100