From 4ed069772107dd34585ec33e27b029fcf856e8a6 Mon Sep 17 00:00:00 2001 From: Yuval Levental Date: Sat, 8 Nov 2025 22:13:51 +0000 Subject: [PATCH 1/2] [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 --- .../math-functions/terms/sincos/sincos.md | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 content/c-sharp/concepts/math-functions/terms/sincos/sincos.md diff --git a/content/c-sharp/concepts/math-functions/terms/sincos/sincos.md b/content/c-sharp/concepts/math-functions/terms/sincos/sincos.md new file mode 100644 index 00000000000..5f9a02b3d60 --- /dev/null +++ b/content/c-sharp/concepts/math-functions/terms/sincos/sincos.md @@ -0,0 +1,75 @@ +--- +Title: '.SinCos()' +Description: 'Returns both the sine and cosine of a given angle.' +Subjects: + - 'Code Foundations' + - 'Computer Science' +Tags: + - 'Methods' + - 'Numbers' + - 'Arithmetic' + - 'Functions' +CatalogContent: + - 'learn-c-sharp' + - 'paths/computer-science' +--- + +The **`Math.SinCos()`** class method returns both the sine and cosine of a given angle as a tuple. + +## Syntax + +```pseudo +Math.SinCos(angle); +``` + +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. + +> **Note:** This method is more efficient than calling `Math.Sin()` and `Math.Cos()` separately when both values are needed. + +## Example + +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: + +```cs +using System; + +public class Example { + public static void Main(string[] args) { + double degrees = 45; + double radians = degrees * Math.PI/180; + + var (sine, cosine) = Math.SinCos(radians); + + Console.WriteLine("The sine of " + degrees + " degrees is: " + sine); + Console.WriteLine("The cosine of " + degrees + " degrees is: " + cosine); + } +} +``` + +The example will result in the following output: + +```shell +The sine of 45 degrees is: 0.7071067811865476 +The cosine of 45 degrees is: 0.7071067811865476 +``` + +## Codebyte Example + +The following example is runnable and returns both the sine and cosine of the `angle` given in degrees: + +```codebyte/csharp +using System; + +public class Example { + + public static void Main(string[] args) { + // Angle in degrees + double angle = 30; + + var (sine, cosine) = Math.SinCos(angle * Math.PI/180); + + Console.WriteLine("The sine of " + angle + " degrees is: " + sine); + Console.WriteLine("The cosine of " + angle + " degrees is: " + cosine); + } +} +``` From fc1b683738e9a961af5a5e4099a8a541989d4bf6 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 10 Nov 2025 12:28:43 +0530 Subject: [PATCH 2/2] minor content fixes --- .../math-functions/terms/sincos/sincos.md | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/content/c-sharp/concepts/math-functions/terms/sincos/sincos.md b/content/c-sharp/concepts/math-functions/terms/sincos/sincos.md index 5f9a02b3d60..50e0bcd5250 100644 --- a/content/c-sharp/concepts/math-functions/terms/sincos/sincos.md +++ b/content/c-sharp/concepts/math-functions/terms/sincos/sincos.md @@ -5,16 +5,16 @@ Subjects: - 'Code Foundations' - 'Computer Science' Tags: - - 'Methods' - - 'Numbers' - 'Arithmetic' - 'Functions' + - 'Methods' + - 'Numbers' CatalogContent: - 'learn-c-sharp' - 'paths/computer-science' --- -The **`Math.SinCos()`** class method returns both the sine and cosine of a given angle as a tuple. +The **`Math.SinCos()`** method returns both the sine and cosine of a specified angle (in radians) as a [tuple](https://www.codecademy.com/resources/docs/python/tuples). ## Syntax @@ -22,13 +22,19 @@ The **`Math.SinCos()`** class method returns both the sine and cosine of a given Math.SinCos(angle); ``` -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. +**Parameters:** + +- `angle`: A double-precision floating-point number representing an angle in radians. + +**Return value:** + +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. > **Note:** This method is more efficient than calling `Math.Sin()` and `Math.Cos()` separately when both values are needed. -## Example +## Example 1 -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: +In this example, the code converts 45 degrees to radians and uses the `Math.SinCos()` method to return both the sine and cosine of that angle: ```cs using System; @@ -53,11 +59,11 @@ The sine of 45 degrees is: 0.7071067811865476 The cosine of 45 degrees is: 0.7071067811865476 ``` -## Codebyte Example +## Example 2 -The following example is runnable and returns both the sine and cosine of the `angle` given in degrees: +In this example, both sine and cosine values of a 30° angle are calculated using `Math.SinCos()`: -```codebyte/csharp +```cs using System; public class Example { @@ -73,3 +79,12 @@ public class Example { } } ``` + +The output of this code is: + +```shell +The sine of 30 degrees is: 0.5 +The cosine of 30 degrees is: 0.8660254037844386 +``` + +> **Note:** The `Math.SinCos()` method is supported starting from .NET 6 and later. It is not available in earlier .NET versions.