Code-Memo

math and math/bits

Common functions
import "math"

x := math.Sqrt(2)
y := math.Pow(2, 10)
z := math.Max(1, 2)
f := math.Mod(7, 3)
Constants

math.Pi, math.MaxFloat64, math.SmallestNonzeroFloat64, etc.

Integer min/max (Go 1.21+)

Prefer max and min builtins, or cmp.Compare.

math/bits

Leading zeros, rotations, population count — hot paths for bitsets and hashing.

import "math/bits"

n := bits.Len64(42)
Caution on floats

Compare with tolerance for accumulated error when modeling real numbers.