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
+10.6k Golang : Fuzzy string search or approximate string matching example
+6.6k Golang : Individual and total number of words counter example
+5.6k Golang : Test input string for unicode example
+11.9k Golang : How to calculate the distance between two coordinates using Haversine formula
+18.7k Golang : Count JSON objects and convert to slice/array
+4.4k Python : Create Whois client or function example
+17.5k Golang : Implement getters and setters
+8.6k Golang : Changing a RGBA image number of channels with OpenCV
+12.8k Golang : unknown escape sequence error
+13.1k Golang : syscall.Socket example
+29k Golang : How to verify uploaded file is image or allowed file types
+18.6k Golang : Close channel after ticker stopped example