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.1k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+11.4k Golang : How to detect a server/machine network interface capabilities?
+22.7k Golang : Randomly pick an item from a slice/array example
+9.1k Golang : How to protect your source code from client, hosting company or hacker?
+7.8k Golang : Get all countries phone codes
+6.8k Golang : Takes a plural word and makes it singular
+52k Golang : How to get struct field and value by name
+9.4k Javascript : Read/parse JSON data from HTTP response
+23.6k Golang : Use regular expression to validate domain name
+5.5k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+5.7k Facebook : How to force facebook to scrape latest URL link data?
+12.3k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard