python / python/cpython

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

Aperta
#153,144 11 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

extension-modules OS-unsupported type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Esamina prima il PR #152825 e il PR #153148 collegato, poiché sembrano risolvere questa segnalazione. Inizia tracciando le implementazioni CPython di math.atan2 e cmath.phase e confrontando il comportamento con icx rispetto a GCC. Il lavoro è completato quando gli argomenti con valore zero non sollevano più ValueError e mantengono i risultati documentati di signed-zero.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
20/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.