Go Tanh()

Sriparno08's avatar
Published Sep 22, 2023Updated Jun 9, 2025
Contribute to Docs

The Tanh() function returns the hyperbolic tangent of a given number.

  • 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"

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) is 0.
  • The result of Tanh(NaN) is NaN.

Example

The following calculates the hyperbolic tangent of 0.5 and prints out the result:

package main
import (
"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.

Code
Output
Loading...

All contributors

Contribute to 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