-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Conversation
Note regarding the 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. |
Tagging subscribers to this area: @dotnet/area-system-numerics Issue DetailsThis resolves #86402
|
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 |
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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! :)
src/libraries/System.Private.CoreLib/src/System/Numerics/ITrigonometricFunctions.cs
Outdated
Show resolved
Hide resolved
…onometricFunctions.cs Co-authored-by: Joe4evr <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great comment
This resolves #86402