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
+3.7k Unix/Linux : How to test user agents blocked successfully ?
+22.2k Golang : Change a file last modified date and time
+5.5k SSL : How to check if current certificate is sha1 or sha2 from command line
+14.1k Golang : Read binary file into memory
+6.1k Golang : Get SPF and DMARC from email headers to fight spam
+5.6k Setting $GOPATH environment variable for Unix/Linux and Windows
+18.3k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+7.3k Golang : flag provided but not defined error
+5k Golang : How to get username from email address
+5.5k Android Studio : Indicate progression with ProgressBar example
+4.2k Golang : Process non-XML/JSON formatted ASCII text file example