python / python/cpython

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

Open
#153,144 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extension-modules OS-unsupported type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review PR #152825 and linked PR #153148 first, since they appear to address this report. Start by tracing the CPython implementations of math.atan2 and cmath.phase and compare behavior under icx with GCC. Done means zero-valued arguments no longer raise ValueError and retain the documented signed-zero results.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.