Go Cosh()

chip0188922695's avatar
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.

  • 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

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.

Code
Output

All contributors

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