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