Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<complex>: Fix exp and polar on NaN/infinity input #1584

Merged
merged 11 commits into from
Aug 17, 2021

Conversation

statementreply
Copy link
Contributor

@statementreply statementreply commented Jan 23, 2021

Works towards #887.

  • Fix exp.
    Also fix the imaginary part of exp(complex{re, -0.0}), which should be negative zero. The current implementation returns positive zero.
  • Fix polar.
    Most of those input cases (except polar(+Inf, finite)) are UB on paper. This PR implements:
    • polar(-rho, theta) = -polar(rho, theta)
    • polar(rho, theta)exp(complex{log(rho), theta}), when signbit(rho) is false

@statementreply statementreply marked this pull request as ready for review January 23, 2021 16:45
@statementreply statementreply requested a review from a team as a code owner January 23, 2021 16:45
@statementreply statementreply marked this pull request as draft January 23, 2021 16:59
@statementreply statementreply changed the title <complex>: Fix complex exp(Inf) and exp(NaN) <complex>: Fix exp and polar on NaN/infinity input Jan 23, 2021
@StephanTLavavej StephanTLavavej added the bug Something isn't working label Jan 24, 2021
Most of them (except `polar(+Inf, finite)`) are UB on paper. This commit
implements:

- `polar(-rho, theta)` = `-polar(rho, theta)`

- `polar(rho, theta)` ~= `exp(complex{log(rho), theta})`, when
  `signbit(rho)` is `false`
@statementreply statementreply marked this pull request as ready for review January 24, 2021 10:43
Base automatically changed from master to main January 28, 2021 00:35
@StephanTLavavej

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@StephanTLavavej

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

Copy link
Member

@StephanTLavavej StephanTLavavej left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this long-standing misbehavior! Please let me know if you'd like me to investigate how to make the code compatible with /clr:pure - I think that avoiding C++20 usage and dealing with the float_control warning should be sufficient, but I can verify that if you want.

stl/inc/complex Outdated Show resolved Hide resolved
stl/inc/complex Outdated Show resolved Hide resolved
stl/src/xmath.hpp Outdated Show resolved Hide resolved
stl/src/xmath.hpp Outdated Show resolved Hide resolved
stl/src/xmath.hpp Outdated Show resolved Hide resolved
stl/src/xlexp.cpp Outdated Show resolved Hide resolved
stl/src/xlexp.cpp Outdated Show resolved Hide resolved
@StephanTLavavej StephanTLavavej removed their assignment Jun 18, 2021
@StephanTLavavej StephanTLavavej self-assigned this Jun 23, 2021
@StephanTLavavej
Copy link
Member

I've pushed a merge with main - it was surprisingly free of manual merge conflicts, despite code being added near a removed shouty banner.

@StephanTLavavej StephanTLavavej removed their assignment Aug 12, 2021
@StephanTLavavej StephanTLavavej self-assigned this Aug 14, 2021
@StephanTLavavej
Copy link
Member

I'm mirroring this to an MSVC-internal PR. It's totally fine to push changes for code review feedback, but please notify me in that case.

@StephanTLavavej
Copy link
Member

Had to push one more change to fix the internal build - the /clr:pure build uses /std:c++14 so we have to avoid terse static_assert.

Copy link
Member

@barcharcraz barcharcraz left a comment

Choose a reason for hiding this comment

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

This does appear to implement advertised behavior, although I mostly checked only that it did not do anything non-conforming (mess with the polar(0,x) case). I observe that the changes to polar are not currently covered by tests, since even after this change the polar llvm tests can not be enabled. We need to make sure to remember to turn those on.

@StephanTLavavej StephanTLavavej merged commit 1ef25f1 into microsoft:main Aug 17, 2021
@StephanTLavavej
Copy link
Member

Thanks for fixing more of these complex bugs! 😹 🐞 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants