Pow()
Published Jun 30, 2023
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
y
is0
orx
is1
, the result is always1
. - If either
x
ory
isNaN
, the result isNaN
. - If
x
is0
, the result depends on the sign and type (odd or not) ofy
. It can be+Inf
,-Inf
, or0
. - If
x
is+Inf
or-Inf
, the result depends on the sign ofy
and can be+Inf
,-Inf
, or0
. - If
x
is a finite negative number andy
is 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
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Go
Learn how to use Go (Golang), an open-source programming language supported by Google!Beginner Friendly6 hours