Skip to content

Commit 801df77

Browse files
4hbabSSwiniarski
andauthored
[Term Entry] Go Math Functions: .Tan() (#2535)
* Create Cos term for golang math function * Create Tan term for golang math function and updated the cos.md and tags.md * Delete tan.md delete tan.md from the PR of cos.md * updated cos.md * Create Tan term for golang math function * Merged conflicts in cos.md * Removed file from PR and updated the tan.md with the reviewed changes * Removed cos file from PR * formatted the tan.md --------- Co-authored-by: SSwiniarski <86081858+SSwiniarski@users.noreply.github.com>
1 parent c516a39 commit 801df77

File tree

1 file changed

+77
-0
lines changed
  • content/go/concepts/math-functions/terms/tan

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
Title: 'Tan()'
3+
Description: 'Returns the tangent of the given angle.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
Tags:
8+
- 'Math'
9+
- 'Trigonometry'
10+
- 'Functions'
11+
CatalogContent:
12+
- 'learn-go'
13+
- 'paths/computer-science'
14+
---
15+
16+
The **`Tan()`** function returns the tangent of an angle given in radians. The `math` library must be imported in order to use this function.
17+
18+
## Syntax
19+
20+
```pseudo
21+
result := math.Tan(angle)
22+
```
23+
24+
Where `result` is the tangent value of `angle`, returned as a float, except under the following circumstances:
25+
26+
- The result of `Tan(-Inf)` is `NaN`
27+
- The result of `Tan(+Inf)` is `NaN`
28+
- The result of `Tan(NaN)` is `NaN`
29+
30+
## Example
31+
32+
The following calculates the tangent of `angle` and prints out the result:
33+
34+
```go
35+
package main
36+
37+
import (
38+
"fmt"
39+
"math"
40+
)
41+
42+
func main() {
43+
angle := math.Pi / 6
44+
tangent := math.Tan(angle)
45+
fmt.Printf("%.1f\n", tangent)
46+
}
47+
```
48+
49+
The output will be:
50+
51+
```shell
52+
0.6
53+
```
54+
55+
## Codebyte Example
56+
57+
The following example is runnable and shows how the `Tan()` function handles infinite values.
58+
59+
```codebyte/golang
60+
package main
61+
62+
import (
63+
"fmt"
64+
"math"
65+
)
66+
67+
func main() {
68+
positiveInfinity := math.Inf(1)
69+
negativeInfinity := math.Inf(-1)
70+
71+
tanPositiveInf := math.Tan(positiveInfinity)
72+
tanNegativeInf := math.Tan(negativeInfinity)
73+
74+
fmt.Printf("The tangent of positive infinity: %f\n", tanPositiveInf)
75+
fmt.Printf("The tangent of negative infinity: %f\n", tanNegativeInf)
76+
}
77+
```

0 commit comments

Comments
 (0)