Go Tan()

4hbab's avatar
Published Jun 28, 2023
Contribute to Docs

The Tan() function returns the tangent of an angle given in radians. The math library must be imported in order to use this function.

  • 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

result := math.Tan(angle)

Where result is the tangent value of angle, returned as a float, except under the following circumstances:

  • The result of Tan(-Inf) is NaN
  • The result of Tan(+Inf) is NaN
  • The result of Tan(NaN) is NaN

Example

The following calculates the tangent of angle and prints out the result:

package main
import (
"fmt"
"math"
)
func main() {
angle := math.Pi / 6
tangent := math.Tan(angle)
fmt.Printf("%.1f\n", tangent)
}

The output will be:

0.6

Codebyte Example

The following example is runnable and shows how the Tan() function handles infinite values.

Code
Output

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