Searches such as golang math, package math maxint32 go documentation, pkg.go.dev math maxint32, maxint8 package math go, maxint64, go math minint64 constant, or go package math maxint64 constant all point at the same place: the standard library math package. Most APIs operate on float64, but the package also exports fixed-width integer limits (math.MaxInt32, math.MinInt64, and friends) that show up in validation, serializers, and protocol code. This page highlights those constants, common float helpers, two small examples, and related math/* packages.
Tested with Go 1.24 on Linux.
Integer limits: math.MaxInt32, math.MinInt64, and pkg.go.dev
The Integer limit values block in package math defines signed and unsigned bounds for 8-, 16-, 32-, and 64-bit types, for example math.MaxInt8, math.MinInt8, math.MaxInt32, math.MinInt32, math.MaxInt64, and math.MinInt64. It also defines math.MaxInt, math.MinInt, and math.MaxUint, which follow the size of Go’s int and uint on the platform you compiled for (32- or 64-bit).
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println("MaxInt32", math.MaxInt32, "MinInt32", math.MinInt32)
fmt.Println("MaxInt64", math.MaxInt64, "MinInt64", math.MinInt64)
fmt.Println("MaxInt8", math.MaxInt8, "MinInt8", math.MinInt8)
}MaxInt32 2147483647 MinInt32 -2147483648
MaxInt64 9223372036854775807 MinInt64 -9223372036854775808
MaxInt8 127 MinInt8 -128The canonical browser reference is pkg.go.dev/math; the constant names in source live in src/math/const.go.
Floating-point constants (Pi, E, roots, logs)
math.Pi, math.E, and related values (Phi, Sqrt2, Ln2, …) are high-precision float64 constants for geometry and analysis. Separate limits such as math.MaxFloat64 describe IEEE 754 extremes.
Common float64 functions (not integers)
Most callables are of the form func Name(x float64) float64—for example math.Sqrt, math.Pow, math.Sin, math.Log, math.Floor, math.Ceil, math.Round, math.Abs, math.Mod, and math.IsNaN. math.Max and math.Min pick the larger or smaller of two float64 values (not the integer constants MaxInt32 / MinInt64). For full tables and edge cases, stay on pkg.go.dev rather than copying long lists into a tutorial.
Example: circle area with math.Pi
package main
import (
"fmt"
"math"
)
func main() {
const rad = 1.2
area := math.Pi * rad * rad
circ := 2 * math.Pi * rad
fmt.Printf("radius %.1f -> area %.6f circumference %.6f\n", rad, area, circ)
}radius 1.2 -> area 4.523893 circumference 7.539822Example: quadratic roots with math.Sqrt
For a*x² + b*x + c = 0 with real roots, discriminant D = b² - 4ac. When D > 0, x = (-b ± √D) / (2a) (parentheses matter—√D must finish before dividing by 2a).
package main
import (
"fmt"
"math"
)
func report(a, b, c float64) {
d := b*b - 4*a*c
switch {
case d > 0:
sd := math.Sqrt(d)
x1 := (-b + sd) / (2 * a)
x2 := (-b - sd) / (2 * a)
fmt.Printf("a=%g b=%g c=%g -> x1=%g x2=%g\n", a, b, c, x1, x2)
case d == 0:
x := -b / (2 * a)
fmt.Printf("a=%g b=%g c=%g -> double root %g\n", a, b, c, x)
default:
fmt.Printf("a=%g b=%g c=%g -> no real roots\n", a, b, c)
}
}
func main() {
report(1, -5, 6) // roots 3 and 2
report(1, 2, 1) // double root -1
report(1, 2, 3) // complex roots
}a=1 b=-5 c=6 -> x1=3 x2=2
a=1 b=2 c=1 -> double root -1
a=1 b=2 c=3 -> no real rootsRelated standard packages under math/*
These live next to math in the tree but are imported with their own paths:
| Import path | Role |
|---|---|
math/big |
Arbitrary-precision integers and rationals |
math/bits |
Bitwise helpers for unsigned integer types |
math/cmplx |
Complex128 math (cmplx.Sqrt, cmplx.Pow, …) |
math/rand |
Pseudo-random numbers (use crypto/rand for security) |
package main
import (
"fmt"
"math/cmplx"
)
func main() {
z := 3 + 1i
fmt.Println(cmplx.Pow(z, 2))
fmt.Println(cmplx.Sqrt(z))
}(8+6i)
(1.755317301824428+0.28484878459314106i)For strings built from math/rand, see generate random string.
Summary
The golang math story splits in two: integer documentation queries (math.MaxInt32, math.MinInt64, math.MaxInt8, …) are answered directly in package math on pkg.go.dev/math, while day-to-day geometry and analysis use float64 helpers like math.Pi and math.Sqrt. Remember math.Max / math.Min operate on floats; use the MaxInt* / MinInt* constants (or built-in min / max on integers in modern Go) when you mean fixed-width integers. For big integers, complex numbers, or secure randomness, move to math/big, math/cmplx, or crypto/rand instead of stretching math alone.

