Go Tanh()
Published Sep 22, 2023Updated Jun 9, 2025
Contribute to Docs
The Tanh() function returns the hyperbolic tangent of a given number.
Syntax
import "math"
result := math.Tanh(number)
Tanh() accepts an argument, number, of type float64 and returns a value of type float64.
Special cases:
- The result of
Tanh(math.Inf(-1))is-1.math.Inf(-1)represents negative infinity, which is-Inf. - The result of
Tanh(math.Inf(+1))is+1.math.Inf(+1)represents positive infinity, which is+Inf. - The result of
Tanh(0)is0. - The result of
Tanh(NaN)isNaN.
Example
The following calculates the hyperbolic tangent of 0.5 and prints out the result:
package mainimport ("fmt""math")func main() {value := math.Tanh(0.5)fmt.Printf("%.2f\n", value)}
The output will be:
0.46
Codebyte
The following example is runnable and shows the Tanh() function handling the value 1.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
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