mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
26 lines
411 B
Go
26 lines
411 B
Go
package mathutil
|
|
|
|
// IntegerSquareRoot defines a function that returns the
|
|
// largest possible integer root of a number.
|
|
func IntegerSquareRoot(n uint64) uint64 {
|
|
x := n
|
|
y := (x + 1) / 2
|
|
|
|
for y < x {
|
|
x = y
|
|
y = (x + n/x) / 2
|
|
}
|
|
return x
|
|
}
|
|
|
|
// CeilDiv8 divides the input number by 8
|
|
// and takes the ceiling of that number.
|
|
func CeilDiv8(n int) int {
|
|
ret := n / 8
|
|
if n%8 > 0 {
|
|
ret++
|
|
}
|
|
|
|
return ret
|
|
}
|