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
+8k Javascript : Put image into Chrome browser's console
+12.9k Golang : Convert IPv4 address to packed 32-bit binary format
+7.2k CloudFlare : Another way to get visitor's real IP address
+18k Golang : Qt image viewer example
+12.5k Golang : Search and extract certain XML data example
+8k Swift : Convert (cast) String to Float
+18k Golang : How to make a file read only and set it to writable again?
+12.2k Golang : Find and draw contours with OpenCV example
+22.3k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+5.5k Golang : What is StructTag and how to get StructTag's value?
+6.6k Golang : Combine slices of complex numbers and operation example
+7k Golang : Fibonacci number generator examples