i32

package
v0.0.0-...-5dc6d85 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2016 License: BSD-3-Clause Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(x int32) int32

Abs returns the absolute value of x.

func BitCount

func BitCount(v int32) int32

Bitcount returns the number of set bits in v. Recall that Go represent integers in two's complement.

func Cbrt

func Cbrt(n int32) int32

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 GCD

func GCD(a, b int32) int32

GCD returns the greatest common divisor of a and b.

func Log10

func Log10(n int32) int32

Log10 returns log base 10 of n. n <= 0 return -1

func Log2

func Log2(n int32) (r int32)

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 Max

func Max(x, y int32) int32

Max(x,y) returns the larger of x or y

func Min

func Min(x, y int32) int32

Min(x,y) returns the smaller of x or y

func Pow

func Pow(x, y int32) (r int32)

Pow returns x**y, the base-x exponential of y.

func Sqrt

func Sqrt(x int32) int32

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

func TrailingZeros(v int32) int32

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL