MathF.Sign() Method in C# with Examples
In C#, MathF.Sign(Single) is a MathF class method which returns an integer that specify the sign of the number.
Syntax: public static int Sign (float x);
Here, x is the required single precision floating-point number whose sign has to be calculated.
Return Type: This method returns the value of type System.Int32 as per following mentioned conditions:
| Return Value | Condition: |
|---|---|
| 0 | If value is equal to zero |
| 1 | If value is greater than zero |
| -1 | If value is lesser than zero |
Example:
// C# program to demonstrate the // MathF.Sign(Single) Method using System; class GFG { // Main Method static void Main(string[] args) { // float data type float f1 = 746.89f; float f2 = -782.1247f; // displaying result Console.WriteLine(check(MathF.Sign(f1))); Console.WriteLine(check(MathF.Sign(f2))); } // function to check whether the input // number is greater than zero or not public static String check(int r) { if (r == 0) return "Equal to zero"; else if (r < 0) return "Less than zero"; else return "Greater than zero"; } } |
chevron_right
filter_none
Output:
Greater than zero Less than zero
Recommended Posts:
- MathF.Exp() Method in C# with Examples
- MathF.Cos() Method in C# with Examples
- MathF.Tan() Method in C# with Examples
- MathF.Abs() Method in C# with Examples
- MathF.Max() Method in C# with Examples
- MathF.Sin() Method in C# with Examples
- MathF.Min() Method in C# with Examples
- MathF.Pow() Method in C# with Examples
- MathF.Log() Method in C# with Examples
- UInt16.ToString Method in C# with Examples | Set - 2
- Int64.CompareTo Method in C# with Examples
- UInt64.ToString Method in C# with Examples | Set - 2
- UInt32.ToString() Method in C# with Examples | Set - 1
- UInt64.ToString() Method in C# with Examples | Set - 1
- UInt32.ToString Method in C# with Examples | Set - 2
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.



