Skip to content

Preserve the imaginary zero sign in complex log1p - #1438

Draft
agourakis82 wants to merge 1 commit into
xtensor-stack:masterfrom
agourakis82:fix/complex-log1p-branch-cut-1432
Draft

agourakis82 wants to merge 1 commit into
xtensor-stack:masterfrom
agourakis82:fix/complex-log1p-branch-cut-1432

Conversation

@agourakis82

@agourakis82 agourakis82 commented Oct 30, 2026 •

Copy link
Copy Markdown

Complex log1p(-2 - 0i) returns +pi instead of -pi in its imaginary component. The complex addition in u = 1 + z adds a positive imaginary zero to the input, losing the negative-zero side of the branch cut before log(u) is evaluated.

Translate only the real component and copy the imaginary component unchanged. Preserve the existing small-input correction. Add mixed-lane float/double coverage on both sides of the cut, immediately below -1, at the origin, and for nonzero-imaginary controls. The reference explicitly constructs (1 + real(z), imag(z)) before scalar std::log so it also preserves the zero sign.

Validation (C++23):

  • ARM64: identical regression fails before the fix (36 assertions); after the fix, all 4 complex-exponential test cases and 264 assertions pass.
  • ASan/UBSan: the same test unit passes.
  • Combined exponential/trigonometric/hyperbolic test units pass.
  • x86_64 SSE2 under Rosetta, Apple Clang: baseline failure and candidate pass confirmed.
  • Physical x86_64 AVX2/FMA, GCC13.3 C++23 on Intel Xeon 6730P: identical baseline tests fail (72 assertions); candidate passes 4 cases / 528 assertions. CPU-only Slurm job 20284 completed with exit 0:0.
  • Native AVX2 composition with Handle zero and infinite argument pairs in atan2 #1439 at 94a8f71 passes 12 cases / 2112 assertions (CPU-only Slurm20310), including infinite argument pairs and both zero signs at the endpoint z = -1. That endpoint remains outside this PR alone.
  • The unchanged original Complex asin, acos, asinh, acosh, sqrt, log1p, tan, tanh return very different results from std:: #1432 reproducer now matches its scalar reference for log1p(-2 - 0i).
  • Formatting and whitespace checks pass.

Addresses the reported log1p branch-cut example in #1432. The exact endpoint z = -1 remains outside this fix: a separate reproducer confirms that existing log(0 +/- 0i) inherits a NaN angle from atan2(0, 0) on the baseline and candidate. New signed-zero assertions are excluded under fast-math. No claim of complete #1432 resolution, nonfinite coverage, exception freedom, full-suite or all-architecture validation.

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