]> Cypherpunks repositories - gostls13.git/commitdiff
math: use shared signMask constant
authormohanson <mohanson@outlook.com>
Tue, 23 Dec 2025 02:44:51 +0000 (10:44 +0800)
committerGopher Robot <gobot@golang.org>
Fri, 23 Jan 2026 16:23:44 +0000 (08:23 -0800)
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
Reviewed-on: https://go-review.googlesource.com/c/go/+/732060
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
src/math/abs.go
src/math/copysign.go

index 08be14548dd778c37411864ad119e859e8855151..945cbd5d86ddb8097f8a2b389da041e7e556b4bd 100644 (file)
@@ -11,5 +11,5 @@ package math
 //     Abs(±Inf) = +Inf
 //     Abs(NaN) = NaN
 func Abs(x float64) float64 {
-       return Float64frombits(Float64bits(x) &^ (1 << 63))
+       return Float64frombits(Float64bits(x) &^ signMask)
 }
index 3a30afb41367e743cc933fbe8405ff98760f96ad..ae9ae35897b99c024f1fc0f011c307d40d988948 100644 (file)
@@ -7,6 +7,5 @@ package math
 // 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)
 }