Go Cosh()
Published Sep 16, 2023
The Cosh() of the math package is an inbuilt function that takes a given value and returns its hyperbolic cosine value.
Syntax
import "math"
CoshX = math.Cosh(x)
Where CoshX is the hyperbolic cosine value of x, it is of type float64. It always returns the hyperbolic cosine value except for some special cases:
Cosh(±0)is1Cosh(±Inf)is+InfCosh(NaN)isNaN
Example
The following Golang program calculates the hyperbolic cosine of x and prints out the result:
package mainimport ("fmt""math")func main() {fmt.Println(math.Cosh(5))fmt.Println(math.Cosh(-5))}
The output will be:
74.2174.21
Codebyte Example
The following example shows how the Cosh() function handles float64 arguments including special cases.
Learn Go on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn how to use Go (Golang), an open-source programming language supported by Google!
- Beginner Friendly.6 hours