[go] math: use shared signMask constant

4 views
Skip to first unread message

Wanbiao Ye (Gerrit)

unread,
Dec 22, 2025, 9:59:21 PM (2 days ago) Dec 22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Wanbiao Ye has uploaded the change for review

Commit message

math: use shared signMask constant

In abs.go and copysign.go, magic numbers and local constants are
used for the sign bit mask (1 << 63), even though a shared constant
signMask already exists in bits.go.
Change-Id: Ic3aeb9b52674538443cbe074acfeb373a3c74a8e

Change diff

diff --git a/src/math/abs.go b/src/math/abs.go
index 08be145..945cbd5 100644
--- a/src/math/abs.go
+++ b/src/math/abs.go
@@ -11,5 +11,5 @@
// Abs(±Inf) = +Inf
// Abs(NaN) = NaN
func Abs(x float64) float64 {
- return Float64frombits(Float64bits(x) &^ (1 << 63))
+ return Float64frombits(Float64bits(x) &^ signMask)
}
diff --git a/src/math/copysign.go b/src/math/copysign.go
index 3a30afb..ae9ae35 100644
--- a/src/math/copysign.go
+++ b/src/math/copysign.go
@@ -7,6 +7,5 @@
// Copysign returns a value with the magnitude of f
// and the sign of sign.
func Copysign(f, sign float64) float64 {
- const signBit = 1 << 63
- return Float64frombits(Float64bits(f)&^signBit | Float64bits(sign)&signBit)
+ return Float64frombits(Float64bits(f)&^signMask | Float64bits(sign)&signMask)
}

Change information

Files:
  • M src/math/abs.go
  • M src/math/copysign.go
Change size: XS
Delta: 2 files changed, 2 insertions(+), 3 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ic3aeb9b52674538443cbe074acfeb373a3c74a8e
Gerrit-Change-Number: 732060
Gerrit-PatchSet: 1
Gerrit-Owner: Wanbiao Ye <lacew...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Robert Griesemer (Gerrit)

unread,
Dec 23, 2025, 2:40:39 PM (yesterday) Dec 23
to Wanbiao Ye, goph...@pubsubhelper.golang.org, Robert Griesemer, Russ Cox, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Robert Griesemer, Russ Cox and Wanbiao Ye

Robert Griesemer voted and added 1 comment

Votes added by Robert Griesemer

Auto-Submit+1
Code-Review+2
Commit-Queue+1

1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Robert Griesemer . resolved

Thanks!

Open in Gerrit

Related details

Attention is currently required from:
  • Robert Griesemer
  • Russ Cox
  • Wanbiao Ye
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedNo-Wait-Release
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ic3aeb9b52674538443cbe074acfeb373a3c74a8e
Gerrit-Change-Number: 732060
Gerrit-PatchSet: 1
Gerrit-Owner: Wanbiao Ye <lacew...@gmail.com>
Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
Gerrit-Reviewer: Robert Griesemer <g...@google.com>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Russ Cox <r...@golang.org>
Gerrit-Attention: Wanbiao Ye <lacew...@gmail.com>
Gerrit-Attention: Robert Griesemer <g...@golang.org>
Gerrit-Comment-Date: Tue, 23 Dec 2025 19:40:35 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages