Skip to content

Handle zero and infinite argument pairs in atan2 - #1439

Closed
agourakis82 wants to merge 1 commit into
xtensor-stack:masterfrom
agourakis82:fix/atan2-signed-zero-1432
Closed

agourakis82 wants to merge 1 commit into
xtensor-stack:masterfrom
agourakis82:fix/atan2-signed-zero-1432

Conversation

@agourakis82

@agourakis82 agourakis82 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

atan2(0, 0) and atan2(inf, inf) divided those pairs and returned NaN, and a pair of zeros lost the signed angle. The non-fast-math path substitutes a unit ratio for those pairs and restores copysign(0 or pi, y) when both arguments are zero. The test crosses two vectors of eight values, including signed zeros and infinities, and compares each batch with std::atan2. Under fast-math, where that recovery is compiled out, the same grid uses finite non-zero stand-ins.

Part of #1432.

Written by me with AI assistance.

@agourakis82 agourakis82 changed the title Handle signed zero pairs without invalid division in atan2 Handle zero and infinite argument pairs in atan2 Oct 30, 2026
@agourakis82

Copy link
Copy Markdown
Contributor Author

Published in a5a3d83.

I integrated the regression cases into the existing typed function tests. The atan2 block now runs the eight finite sample pairs with explicit numerical assertions in both strict and fast-math. The signed-zero and infinity/NaN cases retain narrow strict guards, matching the implementation's exceptional-input contract. The complex log zero-angle cases now live in the existing test_log method.

On macOS ARM64 with Apple Clang 21 and C++23, the expanded scoped tests pass all twelve cases in each mode, with 648 assertions in strict mode and 48 in fast-math. Removing the final atan2 zero-pair correction in a receipt-local header copy causes 36 assertions to fail in strict mode. A separate mutation restricted to the shared finite pairs causes all 48 finite assertions to fail in both modes, confirming that the shared numerical coverage executes.

Prepared with OpenAI Codex assistance.

Avoid 0/0 and inf/inf ratios, and keep the signed angle for a pair of zeros.
@DiamonDinoia

Copy link
Copy Markdown
Contributor

Superseded by #1456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants