[go] math: support Clamp and Clamp01 methods

23 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Jan 30, 2023, 1:50:50 PM1/30/23
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot has uploaded this change for review.

View Change

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.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I08dceede4cf6eaaeb5920a61ae51f10c340d2e22
Gerrit-Change-Number: 463988
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-MessageType: newchange

Gopher Robot (Gerrit)

unread,
Jan 30, 2023, 1:51:38 PM1/30/23
to Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

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.

View Change

    To view, visit change 463988. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I08dceede4cf6eaaeb5920a61ae51f10c340d2e22
    Gerrit-Change-Number: 463988
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Mon, 30 Jan 2023 18:51:34 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Keith Randall (Gerrit)

    unread,
    Jan 30, 2023, 2:00:44 PM1/30/23
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, Gopher Robot, golang-co...@googlegroups.com

    Patch set 1:Hold +1

    View Change

    1 comment:

    To view, visit change 463988. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I08dceede4cf6eaaeb5920a61ae51f10c340d2e22
    Gerrit-Change-Number: 463988
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Mon, 30 Jan 2023 19:00:38 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Gerrit Bot (Gerrit)

    unread,
    May 27, 2023, 9:25:28 AM5/27/23
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Keith Randall, Robert Griesemer, Russ Cox.

    Gerrit Bot uploaded patch set #2 to this change.

    View 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.

    Gerrit-MessageType: newpatchset
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I08dceede4cf6eaaeb5920a61ae51f10c340d2e22
    Gerrit-Change-Number: 463988
    Gerrit-PatchSet: 2
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
    Gerrit-Reviewer: Russ Cox <r...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Attention: Robert Griesemer <g...@golang.org>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Attention: Russ Cox <r...@golang.org>

    Ian Lance Taylor (Gerrit)

    unread,
    May 29, 2023, 7:11:03 PM5/29/23
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Robert Griesemer, Russ Cox, Keith Randall, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Keith Randall, Robert Griesemer, Russ Cox.

    View Change

    1 comment:

    To view, visit change 463988. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I08dceede4cf6eaaeb5920a61ae51f10c340d2e22
    Gerrit-Change-Number: 463988
    Gerrit-PatchSet: 2
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
    Gerrit-Reviewer: Russ Cox <r...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
    Gerrit-Attention: Robert Griesemer <g...@golang.org>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Attention: Russ Cox <r...@golang.org>
    Gerrit-Comment-Date: Mon, 29 May 2023 23:10:59 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No

    Ian Lance Taylor (Gerrit)

    unread,
    May 29, 2023, 7:11:20 PM5/29/23
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Robert Griesemer, Russ Cox, Keith Randall, Gopher Robot, golang-co...@googlegroups.com

    Ian Lance Taylor abandoned this change.

    View Change

    Abandoned Proposal 58146 was declined.

    To view, visit change 463988. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-MessageType: abandon
    Reply all
    Reply to author
    Forward
    0 new messages