Documentation ¶
Index ¶
- func Abs(x int32) int32
- func BitCount(v int32) int32
- func Cbrt(n int32) int32
- func GCD(a, b int32) int32
- func Log10(n int32) int32
- func Log2(n int32) (r int32)
- func Max(x, y int32) int32
- func Min(x, y int32) int32
- func Pow(x, y int32) (r int32)
- func Sqrt(x int32) int32
- func TrailingZeros(v int32) int32
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BitCount ¶
Bitcount returns the number of set bits in v. Recall that Go represent integers in two's complement.
func Cbrt ¶
Cbrt returns the integer cube root of n. That is to say, the r such that:
r * r * r <= n && n < (r + 1) * (r + 1) * (r + 1) //for positive n r * r * r >= n && n > (r + 1) * (r + 1) * (r + 1) //for negative n
Adapted from code found in Hacker's Delight, fixed by Fabian Giessen https://gist.github.com/729557
func Log2 ¶
Log2 returns log base 2 of n. It's the same as index of the highest bit set in n. n <= 0 return -1.
func Sqrt ¶
Sqrt returns the square root of x. x < 0 returns -1. Based on code found in Hacker's Delight (Addison-Wesley, 2003): http://www.hackersdelight.org/
func TrailingZeros ¶
TrailingZeros returns a byte with the number of trailing 0 bits in v. Remember that Go represents negative integers in two's complement. If v is 0, it returns 0.
Types ¶
This section is empty.