Cosh()

Published Sep 16, 2023
Contribute to Docs

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) is 1
  • Cosh(±Inf) is +Inf
  • Cosh(NaN) is NaN

Example

The following Golang program calculates the hyperbolic cosine of x and prints out the result:

package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(math.Cosh(5))
fmt.Println(math.Cosh(-5))
}

The output will be:

74.21
74.21

Codebyte Example

The following example shows how the Cosh() function handles float64 arguments including special cases.

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Go on Codecademy