ADVERTISEMENT
ADVERTISEMENT

Golang math.Tan() Function with Examples

Golang | math.Tan() Function: Here, we are going to learn about the Tan() function of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 04, 2021

math.Tan()

The Tan() function is an inbuilt function of the math package which is used to get the tangent of the given radian value.

It accepts a parameter (x) and returns the tangent of the radian argument x.

Syntax:

func Tan(x float64) float64

Parameter(s):

  • x : The radian value whose tangent is to be found.

Return Value:

The return type of Tan() function is a float64, it returns the tangent of the given radian value.

Special cases:

  • Tan(±0) = ±0
    If the parameter is ±0, the function returns the same value (±0).
  • Tan(±Inf) = NaN
    If the parameter is ±Inf, the function returns NaN.
  • Tan(NaN) = NaN
    If the parameter is NaN, the function returns the same value (NaN).

Example 1:

// Golang program to demonstrate the
// example of math.Tan() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.Tan(1))
	fmt.Println(math.Tan(0.23))
	fmt.Println(math.Tan(-1))
	fmt.Println(math.Tan(-0.23))
	fmt.Println(math.Tan(-1.23))
	fmt.Println(math.Tan(1.23))
	fmt.Println(math.Tan(math.Pi))
	fmt.Println(math.Tan(0))
	fmt.Println(math.Tan(math.Inf(1)))
	fmt.Println(math.Tan(math.Inf(-1)))
	fmt.Println(math.Tan(math.NaN()))
}

Output:

1.557407724654902
0.23414336235146527
-1.557407724654902
-0.23414336235146527
-2.819815734268152
2.819815734268152
-1.2246467991473515e-16
0
NaN
NaN
NaN

Example 2:

// Golang program to demonstrate the
// example of math.Tan() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	var x float64
	var TanX float64

	x = 0
	TanX = math.Tan(x)
	fmt.Printf("Tangent of %.2f is %.2f\n", x, TanX)

	x = 0.23
	TanX = math.Tan(x)
	fmt.Printf("Tangent of %.2f is %.2f\n", x, TanX)

	x = 1
	TanX = math.Tan(x)
	fmt.Printf("Tangent of %.2f is %.2f\n", x, TanX)

	x = -0.23
	TanX = math.Tan(x)
	fmt.Printf("Tangent of %.2f is %.2f\n", x, TanX)

	x = -2
	TanX = math.Tan(x)
	fmt.Printf("Tangent of %.2f is %.2f\n", x, TanX)

	x = math.Pi
	TanX = math.Tan(x)
	fmt.Printf("Tangent of %.2f is %.2f\n", x, TanX)
}

Output:

Tangent of 0.00 is 0.00
Tangent of 0.23 is 0.23
Tangent of 1.00 is 1.56
Tangent of -0.23 is -0.23
Tangent of -2.00 is 2.19
Tangent of 3.14 is -0.00

Golang math Package Constants and Functions »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.