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
+7.9k Golang : Routes multiplexer routing example with regular expression control
+9.9k Golang : Compare files modify date example
+10.9k Golang : Calculate Relative Strength Index(RSI) example
+19.7k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+11.4k Golang : Fuzzy string search or approximate string matching example
+11.1k Golang : Byte format example
+7.2k Golang : Create zip/ePub file without compression(use Store algorithm)
+25.8k Mac/Linux and Golang : Fix bind: address already in use error
+6.1k Golang : Test input string for unicode example
+28.8k Golang : Get first few and last few characters from string
+7.6k Golang : Getting Echo framework StartAutoTLS to work
+4.6k Golang : A program that contain another program and executes it during run-time