Skip to content

Handle zero and infinite argument pairs in atan2 - #1439

Draft
agourakis82 wants to merge 2 commits into
xtensor-stack:masterfrom
agourakis82:fix/atan2-signed-zero-1432
Draft

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

Conversation

@agourakis82

@agourakis82 agourakis82 commented Oct 30, 2026 •

Copy link
Copy Markdown

atan2 forms an invalid ratio when both inputs are zero or both are infinite, producing NaN angles instead of the signed zero/pi or quadrant angle required for those pairs. The zero case also gives log(0 +/- 0i) a NaN imaginary component.

Use safe temporary division operands for these pairs. Preserve the original signs for zero-pair selection and let the existing quadrant calculation handle the unit ratio for infinite pairs. Add mixed-lane float/double coverage for zero pairs, infinite pairs, axes, ordinary quadrants, single-infinite controls, NaN propagation and complex log at signed zeros. Nonzero angles are compared numerically; zero values and their signs are checked exactly.

Validation (C++23):

  • ARM64: the additional infinity regression fails against preceding PR commit 4bc84b2 (60 assertions); the expanded affected units pass with the final patch (10 cases / 732 assertions). ASan/UBSan passes the same units.
  • Native AVX2/FMA, GCC13.3 on Intel Xeon 6730P: identical expanded tests fail against upstream master (312 assertions) and preceding PR commit 4bc84b2 (120 assertions), then pass with the final patch (10 cases / 1464 assertions). CPU-only Slurm20310 completed with exit0:0.
  • Floating-environment witnesses cover all four uniform zero pairs, all four uniform infinite pairs, and mixed exceptional/ordinary lanes. Final ARM64/native-AVX2 witnesses report no FE_INVALID or FE_DIVBYZERO; the preceding implementation returns NaN and raises flags for infinite pairs. No general exception-freedom claim for other inputs.
  • Native AVX2 composition with Preserve the imaginary zero sign in complex log1p #1438 passes 12 cases / 2112 assertions, including both endpoint zero signs in log1p(-1 +/- 0i). This PR remains independently based on master; Preserve the imaginary zero sign in complex log1p #1438 preserves the imaginary sign during log1p translation.
  • Earlier zero-only validation at 4bc84b2 also passed ARM64, ASan/UBSan, translated SSE2 and native AVX2. Current expanded counts above refer to the additional infinite-pair coverage.
  • Formatting and whitespace checks pass.

Related to the endpoint found while investigating #1432. Exceptional-pair handling is excluded under fast-math; infinity coverage is guarded when infinities/NaNs are disabled. Broader overflow, underflow, nonfinite accuracy, a full-suite pass and all-architecture validation remain outside this patch.

@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

This branch has not been deployed

No deployments
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.

1 participant