-
Notifications
You must be signed in to change notification settings - Fork 18k
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
proposal: math: add Clamp function #58146
Comments
What are the proposed function signatures? |
Both of these functions, are parts of so called "standard libraries" in most of programming languages I know (C#, C++, rust). |
Hmm, thinking out loud 🤔 :
|
It is quit useful if you do e.g. percentage operations or something like that. And
Personally, I don't think so. If current
In my opinion deprecating current math is not really necessary. |
Rust has it and, It's better to be math.Clamp only (wihout 01) |
@codenoid "Language X has it" is usually not a viable argument, otherwise Go would have to become a superset of all other languages. |
I dunno, "language X has feature Y" isn't a definitive argument, but it is slight evidence for the usefulness of feature Y. A little bit of counter-evidence is that JavaScript has Math.max and Math.min, but not Math.clamp. I still lean towards math.Clamp being a good idea, but it should be part of a larger generic reorg, like #58559 (comment). |
This proposal has been added to the active column of the proposals project |
math.Clamp(x, min, max float64) float64 seems okay although perhaps not above the bar. math.Clamp01 seems too special-purpose either way. |
Based on the discussion above, this proposal seems like a likely decline. |
@rsc according to the discussion above, it seems that |
@gucio321 Nobody would propose a feature that nobody wants. The question is not: does anybody want this feature? If we followed that guideline, we would add every feature and the result would be an unmanageable and incomprehensible mash of features. The question is: is this feature worth the additional complexity? As @rsc said above, we have a simple guideline today for the math package: anything that is in the C Thanks. |
No change in consensus, so declined. |
somethimes, I need to get a number clamped in a range. I think
math
package would be appropiate to add such aClamp
function.Also, for some percentage calculation,
Clamp01
method is useful as well.(see #58144)
The text was updated successfully, but these errors were encountered: