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
+7.2k SSL : How to check if current certificate is sha1 or sha2 from command line
+5.1k Unix/Linux/MacOSx : How to remove an environment variable ?
+18k Golang : Read binary file into memory
+17.4k Golang : Simple client server example
+4.4k JavaScript: Add marker function on Google Map
+11.6k Golang : Detect user location with HTML5 geo-location
+40.7k Golang : How do I convert int to uint8?
+19.8k Android Studio : AlertDialog and EditText to get user string input example
+6.6k Golang : Fibonacci number generator examples
+11k Golang : Byte format example
+10.1k Golang : Meaning of omitempty in struct's field tag
+31.2k Golang : Convert an image file to []byte