Log2()
function is used to find the binary logarithm of the given input (x
– parameter) in Go language. The standard math package of Go programming language has Log2()
function.
Syntax of Log2()
Function in Go Language
The syntax of Log2()
function in Go Language is:
func Log2(x float64) float64
Note: float64
is a data type in Go language which has IEEE-754 64-bit floating-point numbers.
Special cases are:
Log(+Inf) = +Inf
Log(0) = -Inf
Log(x < 0) = NaN
Log(NaN) = NaN
Parameters of Log2()
Function in Go Language
x
– Where x
is any Valid float64
Input value. This parameter is required.
Error Handling
If the
If there is no argument (
x
parameter is not a number (numeric value) Log2()
function returns an error
.If there is no argument (
x
– input value) passes to the function, then the compiler will produce an error
.
Return Value of Log2()
Function in Go Language
Log2()
function will return the binary logarithm of the given input(x
– parameters).
GoLang Log2()
Function Example 1
package main import "fmt" import "math" func main() { var x float64 x = math.Log2(-2.44) fmt.Println(x) }
Output:
NaN
GoLang Log2()
Function Example 2
package main import "fmt" import "math" func main() { var x float64 x = math.Log2(6.86) fmt.Println(x) }
Output:
2.7782085763980877
GoLang Log2()
Function Example 3
package main import "fmt" import "math" func main() { var x float64 x = math.Log2(4) fmt.Println(x) }
Output:
2