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.
The definition of the Tanh function inside the math package is shown below:
The Tanh function takes a single argument of type float64 that represents the angle whose hyperbolic tangent value you want to find.
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
NANas an argument. In these cases, theTanhfunction returns aNAN.
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
NaNfunction to generate aNANvalue.