Home »
Golang »
Golang Reference
Golang math.Log2E Constant with Examples
Golang | math.Log2E Constant: Here, we are going to learn about the Log2E constant of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on August 25, 2021
math.Log2E Constant
The Log2E constant is an inbuilt constant of the math package which is used to get the base 2 logarithm of the mathematical constant e, approximately equal to 1.442. The math.Log2E constant is equivalent to 1/math.Ln2.
Syntax
float64 math.Log2E
Parameters
Return Value
The return type of math.Log2E constant is float64, it returns the base 2 logarithm of the mathematical constant e.
Example 1
// Golang program to demonstrate the
// example of math.Log2E Constant
package main
import (
"fmt"
"math"
)
func main() {
fmt.Printf("Type of math.Log2E is %T\n", math.Log2E)
fmt.Println("Value of math.Log2E:", math.Log2E)
}
Output:
Type of math.Log2E is float64
Value of math.Log2E: 1.4426950408889634
Explanation:
In the above program, we imported the math package to use the math.Log2E constant, then printed the type and value of the math.Log2E constant.
Example 2
// Golang program to demonstrate the
// example of math.Log2E Constant
package main
import (
"fmt"
"math"
)
// creating function to
// return the value of Log2E.
func getLog2E() float64 {
return math.Log2E
}
func main() {
fmt.Println("Value of math.Log2E:", getLog2E())
}
Output:
Value of math.Log2E: 1.4426950408889634
Golang math Package Constants and Functions »