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
+11.6k Golang : Convert decimal number(integer) to IPv4 address
+21.6k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+8.1k PHP : How to parse ElasticSearch JSON ?
+4.8k Swift : Convert (cast) Float to Int or Int32 value
+11.7k Golang : Save webcamera frames to video file
+5.1k Unix/Linux/MacOSx : How to remove an environment variable ?
+4.7k Golang : Constant and variable names in native language
+5.3k Golang : Shortening import identifier
+13.9k Golang : Get uploaded file name or access uploaded files
+20.1k Golang : Pipe output from one os.Exec(shell command) to another command
+10.2k Golang : Resolve domain name to IP4 and IP6 addresses.
+6.4k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?