math

Math
import "math"

Provides basic constants and mathematical functions (trig, log, exp, etc.).

Example

package main

import (
    "fmt"
    "math"
)

func main() {
    fmt.Println(math.Sqrt(16))    // 4
    fmt.Println(math.Pi)          // 3.14159...
    fmt.Println(math.Max(3, 7))   // 7
}

Key Types & Functions

SqrtAbsMaxMinCeilFloorPiInf

About math

The math package (imported as math) belongs to the Math category of Go packages. Provides basic constants and mathematical functions (trig, log, exp, etc.).

Go's standard library is one of the language's greatest strengths, providing production-ready implementations for networking, cryptography, encoding, I/O, and more. The math package follows Go's philosophy of simplicity and composability — small, focused packages that combine through interfaces like io.Reader and io.Writer.

When using math in production, follow Go best practices: handle errors explicitly, use context for cancellation and timeouts, prefer composition over inheritance, and write table-driven tests. The Go documentation at pkg.go.dev provides comprehensive API references and examples for every exported type and function.

Related Packages