Skip to content

Select the principal branch of complex acosh in both half-planes - #1436

Closed
agourakis82 wants to merge 1 commit into
xtensor-stack:masterfrom
agourakis82:fix/complex-acosh-principal-branch-1432
Closed

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

Conversation

@agourakis82

@agourakis82 agourakis82 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Complex acosh was built as (-imag(acos(z)), real(acos(z))), which leaves the lower half-plane on the wrong branch. It now returns the nonnegative imaginary magnitude of acos and the sign of imag(z). The same change keeps the signed real-axis asin correction, so acosh on the cut agrees with std::acosh. An 8 by 8 grid, including (2, -1) and both sides of the cut, is compared with std::acosh with and without fast-math.

Part of #1432.

Written by me with AI assistance.

@DiamonDinoia DiamonDinoia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is okay but still I need to see a rebase.

@agourakis82
agourakis82 force-pushed the fix/complex-acosh-principal-branch-1432 branch 2 times, most recently from 5ea398a to 68e43b0 Compare November 6, 2026 06:34
Comment thread test/test_complex_hyperbolic.cpp Resolved
@agourakis82
agourakis82 force-pushed the fix/complex-acosh-principal-branch-1432 branch from 68e43b0 to 003ba7e Compare November 8, 2026 19:09
@agourakis82

Copy link
Copy Markdown
Contributor Author

Published in f1ad98f.

I made this candidate self-contained by including the necessary real-axis asin correction already implemented in #1437. Complex acosh uses acos, which in turn uses asin, so the inherited real-axis asin result must preserve both its nonzero imaginary magnitude and the relevant signs. This is the existing #1437 implementation correction reused here.

The existing typed acosh fixtures now include imaginary parts +0 and -0 alongside +1 and -1, over the same eight real values. Numerical comparisons execute in strict and fast-math. Explicit imaginary-zero sign checks remain in strict mode.

On macOS ARM64 with Apple Clang 21 and C++23, the scoped complex hyperbolic and complex trigonometric tests pass four cases in each mode, with 96 assertions in strict mode and 64 in fast-math. Restoring the inherited pre-fix asin implementation in a receipt-local header copy makes the updated regression fail in both modes. A separate C++23 comparison of acosh(±2, ±0) against std::acosh passes all eight float/double cases in both modes for this candidate.

Prepared with OpenAI Codex assistance.

Take the nonnegative imaginary magnitude of acos and the sign of imag(z). Keep the signed real-axis asin branch so the cut matches std::acosh.
@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