INNER CODE UNIT · Go

NextPowerOfTwo

Consensys/gnark-crypto · ecc/utils.go:357

func NextPowerOfTwo(n uint64) uint64 {
	c := bits.OnesCount64(n)
	if c == 0 {
		return 1
	}
	if c == 1 {
		return n
	}
	t := bits.LeadingZeros64(n)
	if t == 0 {
		panic("next power of 2 overflows uint64")
	}
	return uint64(1) << (64 - t)
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…