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
+25.6k Golang : missing Mercurial command
+20.6k Golang : Saving private and public key to files
+21k Golang : Clean up null characters from input data
+11.6k Golang : Secure file deletion with wipe example
+6.7k Golang : Find the longest line of text example
+7.7k Golang : Reverse a string with unicode
+7.7k Golang : How to feed or take banana with Gorilla Web Toolkit Session package
+22.5k Golang : Set and Get HTTP request headers example
+8.9k Golang : How to capture return values from goroutines?
+7.4k SSL : How to check if current certificate is sha1 or sha2 from command line
+20.5k Golang : Secure(TLS) connection between server and client
+21.9k Golang : Join arrays or slices example