Skip to content

Commit 4ed0697

Browse files
committed
[Term Entry] C# Math-functions: SinCos()
Added documentation for the Math.SinCos() method which returns both the sine and cosine of a given angle as a tuple. This method is more efficient than calling Math.Sin() and Math.Cos() separately. Resolves #7953
1 parent dacd022 commit 4ed0697

File tree

1 file changed

+75
-0
lines changed
  • content/c-sharp/concepts/math-functions/terms/sincos

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
Title: '.SinCos()'
3+
Description: 'Returns both the sine and cosine of a given angle.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
Tags:
8+
- 'Methods'
9+
- 'Numbers'
10+
- 'Arithmetic'
11+
- 'Functions'
12+
CatalogContent:
13+
- 'learn-c-sharp'
14+
- 'paths/computer-science'
15+
---
16+
17+
The **`Math.SinCos()`** class method returns both the sine and cosine of a given angle as a tuple.
18+
19+
## Syntax
20+
21+
```pseudo
22+
Math.SinCos(angle);
23+
```
24+
25+
The `Math.SinCos()` method takes only one parameter, `angle`, an angle in radians of type `double`. The method returns a tuple containing both the sine and cosine of the `angle` as `double` values. If the value of `angle` equals `NaN`, `NegativeInfinity`, or `PositiveInfinity`, the method returns `NaN` for both values.
26+
27+
> **Note:** This method is more efficient than calling `Math.Sin()` and `Math.Cos()` separately when both values are needed.
28+
29+
## Example
30+
31+
The following example first converts `45` degrees to radians, then uses the `Math.SinCos()` method to return both the sine and cosine of that angle. Finally, the `Console.WriteLine()` function prints the results to the console:
32+
33+
```cs
34+
using System;
35+
36+
public class Example {
37+
public static void Main(string[] args) {
38+
double degrees = 45;
39+
double radians = degrees * Math.PI/180;
40+
41+
var (sine, cosine) = Math.SinCos(radians);
42+
43+
Console.WriteLine("The sine of " + degrees + " degrees is: " + sine);
44+
Console.WriteLine("The cosine of " + degrees + " degrees is: " + cosine);
45+
}
46+
}
47+
```
48+
49+
The example will result in the following output:
50+
51+
```shell
52+
The sine of 45 degrees is: 0.7071067811865476
53+
The cosine of 45 degrees is: 0.7071067811865476
54+
```
55+
56+
## Codebyte Example
57+
58+
The following example is runnable and returns both the sine and cosine of the `angle` given in degrees:
59+
60+
```codebyte/csharp
61+
using System;
62+
63+
public class Example {
64+
65+
public static void Main(string[] args) {
66+
// Angle in degrees
67+
double angle = 30;
68+
69+
var (sine, cosine) = Math.SinCos(angle * Math.PI/180);
70+
71+
Console.WriteLine("The sine of " + angle + " degrees is: " + sine);
72+
Console.WriteLine("The cosine of " + angle + " degrees is: " + cosine);
73+
}
74+
}
75+
```

0 commit comments

Comments
 (0)