Expose the DegreesToRadians and RadiansToDegrees APIs#88866
Expose the DegreesToRadians and RadiansToDegrees APIs#88866tannergooding merged 4 commits intodotnet:mainfrom
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) |
| /// <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.
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.
GrabYourPitchforks
left a comment
There was a problem hiding this comment.
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 <jii.geugten@gmail.com>
This resolves #86402