Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

GoLang – How to calculate x^y? – Pow() Function – Examples & Explanation

Pow() function is used to find the x^y, the base-x exponential of y. The standard math package of Go programming language has Pow() function.

Syntax of Pow() Function in Go Language

The syntax of Pow() function in Go Language is:

Note: float64 is a data type in Go language which has IEEE-754 64-bit floating-point numbers.
Special cases are:
Pow(x, ±0) = 1 for any x
Pow(1, y) = 1 for any y
Pow(x, 1) = x for any x
Pow(NaN, y) = NaN
Pow(x, NaN) = NaN
Pow(±0, y) = ±Inf for y an odd integer < 0
Pow(±0, -Inf) = +Inf
Pow(±0, +Inf) = +0
Pow(±0, y) = +Inf for finite y < 0 and not an odd integer Pow(±0, y) = ±0 for y an odd integer > 0
Pow(±0, y) = +0 for finite y > 0 and not an odd integer
Pow(-1, ±Inf) = 1
Pow(x, +Inf) = +Inf for |x| > 1
Pow(x, -Inf) = +0 for |x| > 1
Pow(x, +Inf) = +0 for |x| < 1
Pow(x, -Inf) = +Inf for |x| < 1 Pow(+Inf, y) = +Inf for y > 0
Pow(+Inf, y) = +0 for y < 0
Pow(-Inf, y) = Pow(-0, -y)
Pow(x, y) = NaN for finite x < 0 and finite non-integer y

 

Parameters of Pow() Function in Go Language

x, y – Where x and y are Valid float64 Input values. These parameters are required.

 

Error Handling

If the x or y parameters are not numbers (numeric values) Pow() function returns an error .
If there is no argument (x or y – input value) passes to the function, then the compiler will produce an error.

 

Return Value of Pow() Function in Go Language

Pow() function will return x**y, the base-x exponential of y.

 

GoLang Pow() Function Example 1


Output:
-729

 

GoLang Pow() Function Example 2


Output:
4.8828125e+07

 

GoLang Pow() Function Example 3


Output:
NaN

 

Loading...
LearnAndLearn.com © 2018 - All rights reserved