From b7fbbdb11510174650fa1c022ac598664ca33cac Mon Sep 17 00:00:00 2001 From: Prathamesh Shetty Date: Thu, 6 Nov 2025 17:48:15 +0530 Subject: [PATCH 1/2] Add documentation for the Math.Cbrt() method, including syntax, examples, and usage --- .../math-functions/terms/cbrt/cbrt.md | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 content/c-sharp/concepts/math-functions/terms/cbrt/cbrt.md diff --git a/content/c-sharp/concepts/math-functions/terms/cbrt/cbrt.md b/content/c-sharp/concepts/math-functions/terms/cbrt/cbrt.md new file mode 100644 index 00000000000..81c9cdcb503 --- /dev/null +++ b/content/c-sharp/concepts/math-functions/terms/cbrt/cbrt.md @@ -0,0 +1,75 @@ +--- +Title: '.Cbrt()' +Description: 'Returns the cube root of the given number.' +Subjects: + - 'Computer Science' + - 'Code Foundations' +Tags: + - 'Arithmetic' + - 'Numbers' + - 'Methods' +CatalogContent: + - 'learn-c-sharp' + - 'paths/computer-science' +--- + +The **`Math.Cbrt()`** method returns the cube root of the number given. + +## Syntax +```pseudo +Math.Cbrt(x); +``` + +The method takes only one parameter, the variable `x`, of type `double`. The function will return a value of type `double` unless the value passed is one of the following: + +- If `x` is `NaN`, the function will return `NaN`. +- If `x` is `PositiveInfinity`, the function will return `PositiveInfinity`. +- If `x` is `NegativeInfinity`, the function will return `NegativeInfinity`. +- If `x` is negative, the function will return the real cube root (a negative value). + +## Example + +The following example demonstrates the `Math.Cbrt()` method. Four different values are passed to the method, and the return values are printed with the `Console.WriteLine()` method. +```cs +using System; + +namespace MyCubeRoot { + public class Example { + public static void Main(string[] args) { + double a = Math.Cbrt(27); + double b = Math.Cbrt(-8); + double c = Math.Cbrt(1000); + double d = Math.Cbrt(0.125); + + Console.WriteLine(a); + Console.WriteLine(b); + Console.WriteLine(c); + Console.WriteLine(d); + } + } +} +``` + +This example results in the following output: +```shell +3 +-2 +10 +0.5 +``` + +## Codebyte Example + +The following example is runnable and uses the `Math.Cbrt()` method to return a `double` type value of the cube root of `64`: +```codebyte/csharp +using System; + +public class Example { + public static void Main() { + double number = 64; + double cubeRoot = Math.Cbrt(number); + + Console.WriteLine("The cube root of " + number + " is " + cubeRoot); + } +} +``` \ No newline at end of file From 04db0e0939b602a53f72305049664361856adc50 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Fri, 7 Nov 2025 11:47:16 +0530 Subject: [PATCH 2/2] minor content fixes --- .../math-functions/terms/cbrt/cbrt.md | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/content/c-sharp/concepts/math-functions/terms/cbrt/cbrt.md b/content/c-sharp/concepts/math-functions/terms/cbrt/cbrt.md index 81c9cdcb503..a5e244289dd 100644 --- a/content/c-sharp/concepts/math-functions/terms/cbrt/cbrt.md +++ b/content/c-sharp/concepts/math-functions/terms/cbrt/cbrt.md @@ -1,5 +1,5 @@ --- -Title: '.Cbrt()' +Title: 'Cbrt()' Description: 'Returns the cube root of the given number.' Subjects: - 'Computer Science' @@ -13,23 +13,31 @@ CatalogContent: - 'paths/computer-science' --- -The **`Math.Cbrt()`** method returns the cube root of the number given. +The **`Math.Cbrt()`** method in C# returns the cube root of a given number. It handles positive, negative, and special floating-point values such as `NaN` and infinities. ## Syntax + ```pseudo -Math.Cbrt(x); +Math.Cbrt(double x) ``` -The method takes only one parameter, the variable `x`, of type `double`. The function will return a value of type `double` unless the value passed is one of the following: +**Parameters:** + +- `x` (double): The number whose cube root is to be calculated. + +**Return value:** + +The function will return a value of type `double` unless the value passed is one of the following: - If `x` is `NaN`, the function will return `NaN`. - If `x` is `PositiveInfinity`, the function will return `PositiveInfinity`. - If `x` is `NegativeInfinity`, the function will return `NegativeInfinity`. -- If `x` is negative, the function will return the real cube root (a negative value). +- If `x` is negative, returns the real cube root (a negative number). ## Example -The following example demonstrates the `Math.Cbrt()` method. Four different values are passed to the method, and the return values are printed with the `Console.WriteLine()` method. +In this example, different numeric values are passed to `Math.Cbrt()` to calculate their cube roots: + ```cs using System; @@ -51,16 +59,18 @@ namespace MyCubeRoot { ``` This example results in the following output: + ```shell -3 +3.0000000000000004 -2 10 -0.5 +0.49999999999999994 ``` ## Codebyte Example -The following example is runnable and uses the `Math.Cbrt()` method to return a `double` type value of the cube root of `64`: +In this example, the cube root of 64 is calculated using `Math.Cbrt()` and printed to the console: + ```codebyte/csharp using System; @@ -72,4 +82,4 @@ public class Example { Console.WriteLine("The cube root of " + number + " is " + cubeRoot); } } -``` \ No newline at end of file +```