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
+5.3k Golang : Pad file extension automagically
+11.1k Golang : Calculate Relative Strength Index(RSI) example
+6.9k Golang : Levenshtein distance example
+11.4k Golang : Generate DSA private, public key and PEM files example
+14.8k Golang : How to check for empty array string or string?
+5.7k Golang : Find change in a combination of coins example
+14.4k Golang : How to filter a map's elements for faster lookup
+9.8k Golang : Sort and reverse sort a slice of integers
+9.4k Golang : Detect Pascal, Kebab, Screaming Snake and Camel cases
+8.4k Golang : How to check if input string is a word?
+5.1k Golang : Convert lines of string into list for delete and insert operation
+8.4k Golang : Ackermann function example