C# | Math.Sqrt() Method Last Updated : 06 Sep, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report In C#, Math.Sqrt() is a Math class method which is used to calculate the square root of the specified number. Sqrt is a slower computation. It can be cached for a performance boost. Syntax: public static double Sqrt(double d) Parameter: d: Number whose square root is to be calculated and type of this parameter is System.Double. Return Type: This method returns the square root of d. If d is equal to NaN, NegativeInfinity, or PositiveInfinity, that value is returned. The return type of this method is System.Double. Examples: Input : Math.Sqrt(81) Output : 9 Input : Math.Sqrt(-81) Output : NaN Input : Math.Sqrt(0.09) Output : 0.3 Input : Math.Sqrt(0) Output : 0 Input : Math.Sqrt(-0) Output : 0 Below C# programs illustrate the working of Math.Sqrt(): Program 1: When the argument is positive double value then this method returns the square root of a given value. csharp // C# program to illustrate the // Math.Sqrt() method using System; class GFG { // Main Method public static void Main() { double x = 81; // Input positive value, Output square root of x Console.Write(Math.Sqrt(x)); } } Output:9Program 2: When the argument is Negative, this method will return NaN. csharp // C# program to illustrate the Math.Sqrt() // method when the argument is Negative using System; class GFG { // Main method public static void Main() { double x = -81; // Input Negative value, Output square root of x Console.Write(Math.Sqrt(x)); } } Output:NaNProgram 3: When the argument is double value with decimal places, then this method will return the square root of a given value. csharp // C# program to illustrate the Math.Sqrt() // method when the argument is double value // with decimal places using System; class GFG { // Main Method public static void Main() { double x = 0.09; // Input value with decimal places, // Output square root of x Console.Write(Math.Sqrt(x)); } } Output:0.3Program 4: When the argument is positive or negative Zero, then it will return the result as Zero. csharp // C# program to illustrate the Math.Sqrt() // method when the argument is positive // or negative Zero using System; class GFG { // Main Method public static void Main() { double x = 0; // Input value positive Zero, Output // square root of x Console.WriteLine(Math.Sqrt(x)); double y = -0; // Input value Negative Zero, // Output square root of y Console.Write(Math.Sqrt(y)); } } Output:0 0 Note: If the value is too large then it gives the compile time error as error CS1021: Integral constant is too large. Reference: https://msdn.microsoft.com/en-us/library/system.math.sqrt Comment More infoAdvertise with us Next Article C# | Math.Sqrt() Method M Mithun Kumar Follow Improve Article Tags : Misc C# CSharp-method CSharp-Math Practice Tags : Misc Similar Reads JavaScript Math sqrt() Method The JavaScript Math sqrt( ) Method in JavaScript is used to square the root of the number passed as a parameter to the function. Syntax:Math.sqrt(value)Parameters:This method accepts a single parameter as mentioned above and described below: Value: which holds the number whose square root is to be c 2 min read C# | Math.Abs() Method | Set - 1 In C#, Abs() is a Math class method which is used to return the absolute value of a specified number. This method can be overload by passing the different type of parameters to it. Math.Abs(Decimal) Math.Abs(Double) Math.Abs(Int16) Math.Abs(Int32) Math.Abs(Int64) Math.Abs(SByte) Math.Abs(Single) Mat 4 min read MathF.Sqrt() Method in C# with Examples In C#, MathF.Sqrt(Single) is a MathF class(present in system namespace) method which is used to calculate the square root of the specified Single or float data type value. Syntax: public static float Sqrt (float x); Here, x is the number whose square root is to be calculated and type of this paramet 2 min read sqrt, sqrtl and sqrtf in C++ There are various functions available in the C++ Library to calculate the square root of a number. Most prominently, sqrt is used that is defined in <cmath> header file. It takes double as an argument. The <cmath> header defines two more inbuilt functions for calculating the square root 4 min read Java Guava | sqrt(int x, RoundingMode mode) method of IntMath Class The method sqrt(int x, RoundingMode mode) of Guava's IntMath class returns the square root of x, rounded with the specified rounding mode. Syntax: public static int sqrt(int x, RoundingMode mode) Exceptions: IllegalArgumentException: if x < 0. ArithmeticException: if mode is RoundingMode.UNNECESS 3 min read Like