Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

golang
communitycreator

# What is the Tanh function in Golang?

Faraz Karim

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.   The Tanh function in the Go programming language is used to find the hyperbolic tangent value of the angle passed to it as input.

To use the Tanh function, you must import the math package in your file and use the . notation (math.Tanh) to access the Tanh function. Here, Tanh is the actual function, while math is the Go package that stores the definition of this function.

### Syntax

The definition of the Tanh function inside the math package is shown below:

### Parameters

The Tanh function takes a single argument of type float64 that represents the angle whose hyperbolic tangent value you want to find.

### Return value

The Tanh function returns a single value of type float64 that represents the hyperbolic tangent value of the argument. The possible range of all return values is between -1 and +1.

An exception to the above statements is when you pass something that is NAN as an argument. In these cases, the Tanh function returns a NAN.

### Examples

Below is a simple example where we use the Tanh function to find the hyperbolic tangent value of 25:

package mainimport "fmt"import  "math"func main() {		x := math.Tanh(25)	fmt.Println(x)}

The following example shows how passing a NAN as an argument makes the Tanh function return NAN:

package mainimport "fmt"import  "math"func main() {		x := math.Tanh(math.NaN())	fmt.Println(x)}

In the example above, we use the NaN function to generate a NAN value.

RELATED TAGS

golang
communitycreator

CONTRIBUTOR

Faraz Karim

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.   Keep Exploring

Learn in-demand tech skills in half the time 