From: mohanson Date: Tue, 23 Dec 2025 02:44:51 +0000 (+0800) Subject: math: use shared signMask constant X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=23f7ba554d0e3ffbe18d04e79c34984e050869e1;p=gostls13.git 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 Reviewed-on: https://go-review.googlesource.com/c/go/+/732060 LUCI-TryBot-Result: Go LUCI Auto-Submit: Robert Griesemer Reviewed-by: Carlos Amedee Reviewed-by: Robert Griesemer --- diff --git a/src/math/abs.go b/src/math/abs.go index 08be14548d..945cbd5d86 100644 --- a/src/math/abs.go +++ b/src/math/abs.go @@ -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) } diff --git a/src/math/copysign.go b/src/math/copysign.go index 3a30afb413..ae9ae35897 100644 --- a/src/math/copysign.go +++ b/src/math/copysign.go @@ -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) }