mirror of
https://github.com/golang/go.git
synced 2025-10-19 11:03:18 +00:00
cmd/compile: make isUint{32,64}PowerOfTwo implementations clearer
Since these functions cast the input to uint64, so the result always non-negative. The condition should be changed to comparing with zero, thus maaking it clearer to reader, and open room for simplifying in the future by using the generic isUnsignedPowerOfTwo function. Separated this change, so it's easier to do bisecting if there's any problems happened. Change-Id: Ibec28c2590f4c52caa36384b710d526459725e49 Reviewed-on: https://go-review.googlesource.com/c/go/+/692915 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
parent
5ab9f23977
commit
26da1199eb
1 changed files with 2 additions and 2 deletions
|
@ -507,13 +507,13 @@ func isUnsignedPowerOfTwo[T uint8 | uint16 | uint32 | uint64](n T) bool {
|
|||
// isUint64PowerOfTwo reports whether uint64(n) is a power of 2.
|
||||
func isUint64PowerOfTwo(in int64) bool {
|
||||
n := uint64(in)
|
||||
return n > 0 && n&(n-1) == 0
|
||||
return n != 0 && n&(n-1) == 0
|
||||
}
|
||||
|
||||
// isUint32PowerOfTwo reports whether uint32(n) is a power of 2.
|
||||
func isUint32PowerOfTwo(in int64) bool {
|
||||
n := uint64(uint32(in))
|
||||
return n > 0 && n&(n-1) == 0
|
||||
return n != 0 && n&(n-1) == 0
|
||||
}
|
||||
|
||||
// is32Bit reports whether n can be represented as a signed 32 bit integer.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue