Cookies management by TermsFeed Cookie Consent
Russia has invaded Ukraine and already killed tens of thousands of civilians, with many more raped or tortured. It's a genocide. We need your help. Let's fight back against the Russian regime.
Help Ukraine! Fight the Russian regime!

🏋️‍♂️ 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

🧊 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