Cookies management by TermsFeed Cookie Consent

🏋️‍♂️ Calculate the power of a number x^y in Go

shorts numbers math

Please consider supporting us by disabling your ad blocker

To raise a number X to the power of Y in Go, use the Pow(x, y float64) function from the math package.

package main

import (
    "fmt"
    "math"
)

func main() {
    res := math.Pow(2, 7) // 2^7
    fmt.Println(res)
}

Output:

128

To calculate the power of 10 up to the Y exponent in Go, use the math.Pow10(n int) function.

package main

import (
    "fmt"
    "math"
)

func main() {
    res := math.Pow10(3) // 10^3
    fmt.Println(res)
}

Output:

1000

Thank you for being on our site 😊. If you like our tutorials and examples, please consider supporting us with a cup of coffee and we'll turn it into more great Go examples.

Have a great day!

🧊 Cube root in Go

shorts numbers math

🟦 Square root in Go

shorts numbers math

🍰 The maximum and minimum value of the int types in Go

shorts numbers math