-
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
Math & MathF: Conversion constants between degrees and radians #38566
Comments
Tagging subscribers to this area: @tannergooding |
... what's the standard with respect to doing something like calculating the value, instead of a literal constant. Eg: namespace System
{
public static class Math
{
+ public const double RadiansToDegrees = 180.0 / PI;
+ public const double DegreesToRadians = 1.0 / RadiansToDegrees;
}
} |
I think these should be functions rather than constants. Functions will allow a more precise implementation to be provided or for other optimizations to occur, without restricting things. |
Can we have both? What about the vector situation? |
When dealing with floating-point, defining a constant using the precisely computed value is generally better than using a constant expression.
However, computing the same using an expression gives:
So, while |
+1 for the use of constant with expression value ( ie. |
Surprised this is still missing from the built-in Would be nice to just have constants or easy to use |
Constants are a non-starter for the reasons I gave above. If someone wants to open a new proposal, in the appropriate format, covering functions then I'd be willing to take it forward. Please keep in mind that new functions are being exposed on the primitive types directly and may need to update the appropriate |
To list some prior art in this area... Unity has these constants:
Microsoft XNA/MonoGame has these methods:
NetToplogySuite has these methods:
|
Functions remain the only path I'd be willing to drive forward for the reasons given above. This remains a case where if someone opens a proposal covering the functions I'd be happy to mark it Such functions should likely be DIMs hanging off of |
Feels like these belong on ITrigonometricFunctions: namespace System.Numerics {
public interface ITrigonometricFunctions<TSelf> {
+ public static abstract TSelf ToDegrees(TSelf radians);
+ public static abstract TSelf ToRadians(TSelf degrees);
}
} Would we also add sugar for them on Math and MathF? namespace System
{
public static class Math
{
+ public static double ToDegrees(double radians) => radians.ToDegrees();
+ public static double ToRadians(double degrees) => degrees.ToDegrees();
}
public static class MathF
{
+ public static float ToDegrees(float radians) => radians.ToDegrees();
+ public static float ToRadians(float degrees) => degrees.ToDegrees();
}
} |
That sounds like a good place to me given their general usage. Could you open a new issue with the proposed surface and link back to this issue?
This will probably be discussed in API review since this will be the first really "new" API since we introduced the generic math interfaces. My expectation is "no" and that their existence directly as |
I can, but... How would it be different than this one? Isn't this one just iterating on the design of a feature for converting between radians and degrees? Seems kinda silly to open a new issue every time the proposed design of a feature changes. Wouldn't you lose all the context and feedback from upvotes and comments? Prioritization would be biased toward features initially proposed with acceptable designs with no regard for functionality. It's madness!! lol, but yeah, I'll open a new issue. |
API review expects the top post to contain the proposal and summarize discussion points when/where appropriate. Updating this issue would require editing the original post to contain the new info, which is generally undesirable.
In this case, the premise behind the idea is the same, but the actual proposed surface is significantly different. Mentioning other proposals by referencing them helps ensure the relevant context isn't lost, but also avoids polluting the main proposal. Consider that this issue was more a discussion (just created before GitHub discussions existed), rather than a proposal, and that the new thing is the actual proposal. |
Filed #86402. Everyone, please review (and upvote) to make sure I adequately covered your scenarios and incorporated your feedback. |
Closing this in favor of #86402 |
Background and Motivation
My use-case is working with quaternions, since the inputs for
Quaternion.CreateFromYawPitchRoll(...)
are in radians.Proposed API
Don't quote me on the values, and add more precision to the
double
variant.float
should have 9 decimal places, anddouble
should have 29.Usage Examples
Alternative Designs
vector * MathF.DegreesToRadians;
public Vector3 DegreesToRadians(this Vector3 vector) => new Vector2(MathF.DegreesToRadians(vector.X), MathF.DegreesToRadians(vector.Y));
Risks
None.
The text was updated successfully, but these errors were encountered: