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

Potential improvements for System.Numerics.Complex #104233

Closed
lilinus opened this issue Jul 1, 2024 · 2 comments
Closed

Potential improvements for System.Numerics.Complex #104233

lilinus opened this issue Jul 1, 2024 · 2 comments
Labels
area-System.Numerics help wanted [up-for-grabs] Good issue for external contributors

Comments

@lilinus
Copy link
Contributor

lilinus commented Jul 1, 2024

I have found a number of potential places for improvements in System.Numerics.Complex:

  1. Use Math.SinCos when available in various places.
  2. Use double.Hypot when available in Complex.Hypot
  3. sinh and cosh are calculated simultaneously as:
double p = Math.Exp(x);
double q = 1 / p;
double sinh = (p - q) * 0.5;
double cosh = (p + q) * 0.5;

This is inaccurate for sinh due to catastrophic cancellation of p-q when x is close to zero.
Could perhaps be solved by using Math.Sinh and Math.Cosh within a threshold?

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jul 1, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

@tannergooding
Copy link
Member

Please feel free to submit a PR for each of these.

For 3, we should just always call Math.Sinh and Math.Cosh to avoid potential inaccuracies and ensure IEEE 754 compliant results.

@tannergooding tannergooding added help wanted [up-for-grabs] Good issue for external contributors and removed untriaged New issue has not been triaged by the area owner labels Jul 1, 2024
@lilinus lilinus closed this as completed Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Numerics help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

No branches or pull requests

2 participants