Open In App

MathF.Sign() Method in C# with Examples

Last Updated : 04 Apr, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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";
    }
}


Output:

Greater than zero
Less than zero

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads