-
Notifications
You must be signed in to change notification settings - Fork 5k
Math.Min<T> Max<T> Clamp<T> #43796
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
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
|
Tagging subscribers to this area: @tannergooding, @pgovind, @jeffhandley |
Generic min / max / clamp methods seem worthwhile. But the names feel a bit wrong (first / last? before / after?), and string first = Math.Min("foo", "bar"); // would compile and return a logical result I don't have better recommendations unfortunately. :( |
What about Comparer.Min/Max/Clamp? Or some new Comparable class? But this way Math still would need specified methods and Comparer class would have generic ones?... |
@En3Tho Excellent idea! |
Related: #18481 |
@TonyValenti, could you update the original post with the updated API proposal? It sounds like users are wanting to add this to |
@tannergooding Updated. |
This might be feasible with the generic math interfaces that are being proposed. |
Closing. This is now feasible using the generic math interfaces. In particular anything |
Background and Motivation
Please make it easier to min/max/clamp any classes.
Proposed API
Right now the Math.Min / Max / Clamp methods only work with a small number of built in data types. A generic version of these methods should be introduced on the
Comparer<T>
base class.Example Implementation
Usage Examples
Comparer.Clamp(MyValue, TimeSpan.Zero, TimeSpan.FromSeconds(30))
Alternative Designs
This could just be ignored.
Risks
None.
The text was updated successfully, but these errors were encountered: