Go Pow()
Published Jun 30, 2023Updated May 29, 2025
Contribute to Docs
The Pow() function returns the base x raised to the power y. The math library must be imported in order to use this function.
Syntax
result := math.Pow(x, y)
Where result is the value of x raised to the power y, returned as a float64, except under the following circumstances:
- If
yis0orxis1, the result is always1. - If either
xoryisNaN, the result isNaN. - If
xis0, the result depends on the sign and type (odd or not) ofy. It can be+Inf,-Inf, or0. - If
xis+Infor-Inf, the result depends on the sign ofyand can be+Inf,-Inf, or0. - If
xis a finite negative number andyis a finite non-integer, the result isNaN.
Example
The following example calculates the result of base raised to the power exponent and prints out the result:
package mainimport ("fmt""math")func main() {c := math.Pow(2, 3)fmt.Printf("%.1f", c)}
The output will be:
8.0
Codebyte Example
The following example is runnable and shows how the Pow() function can be used in a program:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Go on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn how to use Go (Golang), an open-source programming language supported by Google!
- Beginner Friendly.6 hours