Skip to content

Preserve imaginary sign in complex tan overflow handling - #1434

Closed
agourakis82 wants to merge 1 commit into
xtensor-stack:masterfrom
agourakis82:fix/complex-tan-overflow-sign-1432
Closed

agourakis82 wants to merge 1 commit into
xtensor-stack:masterfrom
agourakis82:fix/complex-tan-overflow-sign-1432

Conversation

@agourakis82

@agourakis82 agourakis82 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Complex tan used to saturate the imaginary part to +1 whenever sinh(2*imag(z)) overflowed, so tan(1, -45) and tan(1, -356) came back with a positive imaginary part. The non-fast-math path now copies the sign of that overflow onto the saturated one. The test fills an 8 by 8 real/imaginary grid, including those magnitudes and signed zeros, and compares each batch with std::tan. The grid is left out of fast-math builds, where this recovery is not compiled and the kernel does not match std::tan.

Part of #1432.

Written by me with AI assistance.

@agourakis82
agourakis82 marked this pull request as ready for review October 28, 2026 09:10

@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.

Same here it seems okay. But needs a rebase

@agourakis82
agourakis82 force-pushed the fix/complex-tan-overflow-sign-1432 branch 2 times, most recently from 230dfd0 to 17bef76 Compare November 6, 2026 06:34

@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.

I think the feedback from before Applies here too.

Fix looks fine but tests are overly complicated.

Think on how to populate batches with real-im pair (is fine to overtest 64 combinations) instead of 20 handpicked ones where you generate the combinations. Then you iterate in a simd and normal scalr fashion and check against std.

Check if you need fast math checks for this test or if it passes with and without. It is fine to test some more cases.

Please, apply this feedback to all the PRs.

@agourakis82

Copy link
Copy Markdown
Contributor Author

Sure!! Thanks for the support and patience!!!

When sinh(2*imag(z)) overflows, keep that sign on the saturated imaginary part.
@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