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

Expose the DegreesToRadians and RadiansToDegrees APIs #88866

Merged
merged 4 commits into from
Jul 14, 2023

Conversation

tannergooding
Copy link
Member

This resolves #86402

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost assigned tannergooding Jul 13, 2023
@ghost
Copy link

ghost commented Jul 13, 2023

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

Issue Details

This resolves #86402

Author: tannergooding
Assignees: -
Labels:

area-System.Numerics, new-api-needs-documentation

Milestone: -

@GrabYourPitchforks
Copy link
Member

I think the order of operations leads to a loss of precision here. From Sharplab:

Console.WriteLine(DegToRads1(double.MaxValue));
Console.WriteLine(DegToRads2(double.MaxValue));

static double DegToRads1(double deg) => (deg * Math.PI) / 180.0;
static double DegToRads2(double deg) => deg * (Math.PI / 180.0);

Output:

∞
3.1375664143845866E+306

@tannergooding
Copy link
Member Author

That’s expected due to the type precision and input domain (as well as general limitations with how we can validly implement the DIM).

The same thing can happen for other pairs of functions as well (like exp and log, cos and acos, etc)

@@ -62,6 +62,54 @@ public interface ITrigonometricFunctions<TSelf>
/// <returns>The value of <paramref name="degrees" /> converted to radians.</returns>
static virtual TSelf DegreesToRadians(TSelf degrees)
{
// We don't want to simplify this to: degrees * (Pi / 180)
Copy link
Member Author

Choose a reason for hiding this comment

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

Added a lengthy comment to this API here and pointed the other implementations to it to help avoid people trying to change the algorithm without considering the edge cases.

Copy link
Member

@GrabYourPitchforks GrabYourPitchforks left a comment

Choose a reason for hiding this comment

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

Appreciate the comment - thank you! :)

Copy link
Member

@danmoseley danmoseley left a comment

Choose a reason for hiding this comment

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

Great comment

@tannergooding tannergooding merged commit 40480e8 into dotnet:main Jul 14, 2023
168 of 172 checks passed
@tannergooding tannergooding deleted the fix-86402 branch July 14, 2023 05:52
@ghost ghost locked as resolved and limited conversation to collaborators Aug 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Convert between degrees and radians
5 participants