python / python/cpython

ValueError for `math.atan2(0.0, 0.0)` and `cmath.phase(0.0)` using icx

オープン
#153,144 コメント 11 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. 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

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

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