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
+16.3k CodeIgniter/PHP : Create directory if does not exist example
+32.3k Golang : Copy directory - including sub-directories and files
+20.5k Nginx + FastCGI + Go Setup.
+7.2k Golang : How to iterate a slice without using for loop?
+55.1k Golang : Unmarshal JSON from http response
+19.9k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+20.2k Swift : Convert (cast) Int to int32 or Uint32
+24k Golang : Find biggest/largest number in array
+8k Golang : Check from web if Go application is running or not
+6.8k Get Facebook friends working in same company
+25.8k Golang : How to read integer value from standard input ?
+12.8k Python : Convert IPv6 address to decimal and back to IPv6