People searching golang power, golang math pow, math.pow golang, or go math.pow usually want one thing: raise a number to an exponent in Go. The standard answer is math.Pow, which implements x to the y for float64 inputs and result. This page shows a correct golang math pow example, explains why int arguments do not compile without a cast, and calls out overflow and NaN rules so power in golang code matches what the math package actually guarantees. For converting numeric types in general, see type casts in Go.
Checked with Go 1.24 on 64-bit Linux (Fedora and Ubuntu family).
golang math.pow: math.Pow for x to the y
Signature and meaning
func Pow(x, y float64) float64math.Pow returns x raised to the power y. Both parameters are float64; there is no overload for int. The implementation follows floating-point rules (including infinities and NaNs); the full special-case table lives in the package documentation. Notable cases: any finite x with exponent ±0 yields 1; a finite negative x with a finite non-integer y yields NaN because no real result exists.
golang math pow examples
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(math.Pow(2, 9)) // 512
fmt.Println(math.Pow(4.5, 2)) // 20.25
fmt.Println(math.Pow(1520, 0)) // 1
}You should see three lines: 512, 20.25, and 1.
go math pow with integer operands
This does not compile because math.Pow expects float64:
cannot use a (variable of type int) as type float64 in argument to math.PowTypical fix: convert, compute, then convert back if you truly need an int result:
package main
import (
"fmt"
"math"
)
func main() {
a, b := 4, 10
fmt.Println(int(math.Pow(float64(a), float64(b)))) // 1048576
}That pattern is only safe when the mathematical result fits exactly in a float64 mantissa and in the int range; large exponents quickly overflow or round wrong. For nonnegative integer exponents and exact integers, exponentiation by squaring stays in integer arithmetic:
package main
import "fmt"
func intPow(x, n int) int {
if n < 0 {
panic("example assumes n >= 0")
}
if n == 0 {
return 1
}
if n == 1 {
return x
}
half := intPow(x, n/2)
if n%2 == 0 {
return half * half
}
return x * half * half
}
func main() {
fmt.Println(intPow(4, 10))
}For very large values use math/big.
golang math power helpers
For 10 raised to an int exponent as float64, math.Pow10 is a readable shortcut where your Go version documents it. For powers of two with small nonnegative exponents, a left shift 1 << k computes two to the power k in integer math without calling Pow.
Summary
Golang math power for floating-point bases and exponents is normally math.Pow, which matches searches for golang math.pow, math pow golang, and go math.pow. Arguments must be float64; casting int values fixes the compile error but can hide precision loss and overflow, so prefer integer algorithms or math/big when the result must be exact. Read the pkg.go.dev edge-case list whenever inputs can be zero, negative, or fractional, because NaN and infinities follow IEEE rules, not grade-school algebra alone.

