Gerrit Bot has uploaded this change for review.
math: support Clamp and Clamp01 methods
Change-Id: I08dceede4cf6eaaeb5920a61ae51f10c340d2e22
GitHub-Last-Rev: e0f5a513b8e33f4941f3357a4b6f7ac56fc3244d
GitHub-Pull-Request: golang/go#58144
---
M src/math/dim.go
1 file changed, 30 insertions(+), 0 deletions(-)
diff --git a/src/math/dim.go b/src/math/dim.go
index 6a286cd..912ef9a 100644
--- a/src/math/dim.go
+++ b/src/math/dim.go
@@ -92,3 +92,22 @@
}
return y
}
+
+// Clamp returns the Number closest to `a`, but in range <min, max>
+//
+// Restrictions:
+//
+// if min > max, Clamp will return NaN
+func Clamp(a, min, max float64) float64 {
+ if min > max {
+ return NaN
+ }
+ a = Min(a, max)
+ a = Max(a, min)
+ return a
+}
+
+// Clamp01 is a special variant of Clamp, where min=0 and max=1
+func Clamp01(a float64) float64 {
+ return Clamp(a, 0, 1)
+}
To view, visit change 463988. To unsubscribe, or for help writing mail filters, visit settings.
Congratulations on opening your first change. Thank you for your contribution!
Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.
Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.
During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11 or adds a tag like "wait-release", it means that this CL will be
reviewed as part of the next development cycle. See https://go.dev/s/release
for more details.
Patch set 1:Hold +1
1 comment:
Patchset:
Additional API like this needs to go through the proposal process.
https://github.com/golang/proposal
To view, visit change 463988. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Keith Randall, Robert Griesemer, Russ Cox.
Gerrit Bot uploaded patch set #2 to this change.
math: support Clamp and Clamp01 methods
Change-Id: I08dceede4cf6eaaeb5920a61ae51f10c340d2e22
GitHub-Last-Rev: b35c10cdcea411968f17b07092f76ba859d6afda
GitHub-Pull-Request: golang/go#58144
---
M src/math/dim.go
1 file changed, 19 insertions(+), 0 deletions(-)
To view, visit change 463988. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Keith Randall, Robert Griesemer, Russ Cox.
1 comment:
Patchset:
Thanks, but new API like this requires a proposal. See https://go.dev/s/proposal.
In this case there already is a proposal, https://go.dev/issue/58146, but the proposal was rejected. So we aren't going to do this.
To view, visit change 463988. To unsubscribe, or for help writing mail filters, visit settings.