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
+23.3k Find and replace a character in a string in Go
+7.3k Gogland : Single File versus Go Application Run Configurations
+6.6k Default cipher that OpenSSL used to encrypt a PEM file
+11.1k Golang : Characters limiter example
+10.5k Golang : Get currencies exchange rates example
+6.2k Golang : Handling image beyond OpenCV video capture boundary
+10k Golang : cannot assign type int to value (type uint8) in range error
+9.1k Golang : Play .WAV file from command line
+22.3k Golang : Set and Get HTTP request headers example
+7.6k Javascript : How to check a browser's Do Not Track status?
+6.9k Golang : Array mapping with Interface
+5.2k Python : Delay with time.sleep() function example