Home »
Golang »
Golang Reference
Golang math.Cosh() Function with Examples
Golang | math.Cosh() Function: Here, we are going to learn about the Cosh() function of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on August 29, 2021
math.Cosh()
The Cosh() function is an inbuilt function of the math package which is used to get the hyperbolic cosine of the given value.
It accepts one parameter and returns the hyperbolic cosine.
Syntax
func Cosh(x float64) float64
Parameters
- x : The value whose hyperbolic cosine is to be found.
Return Value
The return type of Cosh() function is a float64, it returns the hyperbolic cosine value of the given value.
Special cases are:
- Cosh(±0) = 1
If the parameter is ±0, it returns the 1.
- Cosh(±Inf) = +Inf
If the parameter is ±Inf, it returns the +Inf.
- Cosh(NaN) = NaN
If the parameter is NaN, it returns the NaN.
Example 1
// Golang program to demonstrate the
// example of math.Cosh() Function
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(math.Cosh(1))
fmt.Println(math.Cosh(10))
fmt.Println(math.Cosh(-1))
fmt.Println(math.Cosh(-10))
fmt.Println(math.Cosh(0.5))
fmt.Println(math.Cosh(-0.5))
fmt.Println(math.Cosh(0))
fmt.Println(math.Cosh(math.Inf(1)))
fmt.Println(math.Cosh(math.Inf(-1)))
fmt.Println(math.Cosh(math.NaN()))
}
Output:
1.5430806348152437
11013.232920103324
1.5430806348152437
11013.232920103324
1.1276259652063807
1.1276259652063807
1
+Inf
+Inf
NaN
Example 2
// Golang program to demonstrate the
// example of math.Cosh() Function
package main
import (
"fmt"
"math"
)
func main() {
var x float64
var CoshX float64
x = 0
CoshX = math.Cosh(x)
fmt.Println("Coshine value of", x, "is", CoshX)
x = 0.23
CoshX = math.Cosh(x)
fmt.Println("Hyperbolic cosine value of", x, "is", CoshX)
x = 1
CoshX = math.Cosh(x)
fmt.Println("Hyperbolic cosine value of", x, "is", CoshX)
x = -0.23
CoshX = math.Cosh(x)
fmt.Println("Hyperbolic cosine value of", x, "is", CoshX)
x = -2
CoshX = math.Cosh(x)
fmt.Println("Hyperbolic cosine value of", x, "is", CoshX)
x = math.Inf(1)
CoshX = math.Cosh(x)
fmt.Println("Hyperbolic cosine value of", x, "is", CoshX)
x = math.Inf(-1)
CoshX = math.Cosh(x)
fmt.Println("Hyperbolic cosine value of", x, "is", CoshX)
x = math.NaN()
CoshX = math.Cosh(x)
fmt.Println("Hyperbolic cosine value of", x, "is", CoshX)
}
Output:
Coshine value of 0 is 1
Hyperbolic cosine value of 0.23 is 1.026566806216406
Hyperbolic cosine value of 1 is 1.5430806348152437
Hyperbolic cosine value of -0.23 is 1.026566806216406
Hyperbolic cosine value of -2 is 3.7621956910836314
Hyperbolic cosine value of +Inf is +Inf
Hyperbolic cosine value of -Inf is +Inf
Hyperbolic cosine value of NaN is NaN
Golang math Package Constants and Functions »