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 parameter is System.Single.
Return Type: This method returns the square root of x. If x is equal to NaN, NegativeInfinity, or PositiveInfinity, that value is returned. The return type of this method is System.Single.
Below are the examples to illustrate the use of the above-discussed method:
Example 1:
// C# program to demonstrate the // MathF.Sqrt(Single) Method using System; class GFG { // Main Method public static void Main() { // taking positive value float x = 78521F; // taking negative value float x1 = -7824F; // Input positive value // Output will be square // root of x Console.WriteLine(MathF.Sqrt(x)); // Input negative value, // Output will be NaN Console.Write(MathF.Sqrt(x1)); } } |
280.216 NaN
Example 2:
// C# program to demonstrate the MathF.Sqrt() // method when the argument is positive // or negative Zero using System; class GFG { // Main Method public static void Main() { // taking positive zero float x = 0f; Console.WriteLine(MathF.Sqrt(x)); // taking negative zero float y = -0f; Console.Write(MathF.Sqrt(y)); } } |
0 0
Recommended Posts:
- MathF.Min() Method in C# with Examples
- MathF.Pow() Method in C# with Examples
- MathF.Cos() Method in C# with Examples
- MathF.Max() Method in C# with Examples
- MathF.Abs() Method in C# with Examples
- MathF.Sin() Method in C# with Examples
- MathF.Exp() Method in C# with Examples
- MathF.Log() Method in C# with Examples
- MathF.Tan() Method in C# with Examples
- Int64.Equals Method in C# with Examples
- Int32.Equals Method in C# with Examples
- Int32.CompareTo Method in C# with Examples
- Int16.GetTypeCode Method in C# with Examples
- Double.CompareTo Method in C# with Examples
- Int32.GetTypeCode Method in C# with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



