Golang : Math pow(the power of x^y) example
No programming language will be complete without the power of
math function. This tutorial is a simple example on how to use math.Pow()
function.
In Math
2^5 = 2x2x2x2x2 =32
In Golang
Math.pow(2, 5)
In code :
package main
import (
"fmt"
"math"
)
func main() {
result := math.Pow(2, 5)
fmt.Println(" 2 power of 5 is : ", result)
x := 10.5
y := 5
floatResult := math.Pow(x, float64(y)) //type cast int to float64
fmt.Printf(" %.02f power of %d is : %.02f \n", x, y, floatResult)
}
2 power of 5 is : 32
10.50 power of 5 is : 127628.16
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+11.9k Golang : Verify token from Google Authenticator App
+33k Golang : Get file last modified date and time
+6k Golang : File system scanning
+12.9k Golang : package is not in GOROOT during compilation
+17.2k Golang : How to run your code only once with sync.Once object
+10.3k Golang : Change date format to yyyy-mm-dd
+13.2k Golang : How to login and logout with JWT example
+4.6k Unix/Linux : How to test user agents blocked successfully ?
+13.2k Golang : How to check if IP address is in range
+1.6k Golang : Fix go-cron set time not working issue
+5.4k Restart Apache or Nginx web server without password prompt
+22.6k Golang : Call function from another package