ValueError for `math.atan2(0.0, 0.0)` and `cmath.phase(0.0)` using icx
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Revise primeiro o PR #152825 e o PR #153148 vinculado, pois eles parecem tratar deste relatório. Comece rastreando as implementações de CPython de math.atan2 e cmath.phase e comparando o comportamento com icx em relação ao GCC. Considera-se concluído quando os argumentos com valor zero não levantarem mais ValueError e preservarem os resultados documentados de signed-zero.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- backend
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 20/100