C# | Math.Sign() Method - GeeksforGeeks

31 Jan, 2019
In C#, Sign() is a math class method which returns an integer that specify the sign of the number. This method can be overloaded by changing the data type of the passed arguments as follows:
Math.Sign(Decimal): Returns the integer that specifies the sign of a decimal number.
Math.Sign(Double): Returns the integer that specifies the sign of a double-precision floating-point number.
Math.Sign(Int16): Returns the integer that specifies the sign of a 16-bit signed integer. Here Int16 is short data type
Math.Sign(Int32): Returns the integer that specifies the sign of a 32-bit signed integer. Here Int32 is int data type.
Math.Sign(Int64): Returns the integer that specifies the sign of a 64-bit signed integer. Here Int64 is long data type.
Math.Sign(SByte): Returns the integer that specifies the sign of an 8-bit signed integer.
Math.Sign(Single): Returns the integer that specifies the sign of a single-precision floating-point number. Here single is float data type.
Common Syntax for all above methods:
public static int Sign(data_type value)

Parameter: This method takes a single parameter in the form of either bytes, int, double, sbyte, etc.
Return type : This method returns the value of type System.Int32 as per following mentioned conditions:
Example:
// C# program to demonstrate the // Math.Sign() methodusing System;  class GFG {          // Main Method    static void Main(string[] args)    {          // Decimal data type        Decimal de = 150M;                  // Double data type        Double d = 34.5432d;                  // Int16 data type        short sh = 0;                  // Int32 data type        int i = -5678;                  // Int64 data type        long l = 598964564;                  // SByte data type        sbyte sb = -34;                  // float data type        float f = 56.89f;                            // displaying result        Console.WriteLine("Decimal: " + de + " " + check(Math.Sign(de)));        Console.WriteLine("Double: " + d + " " + check(Math.Sign(d)));        Console.WriteLine("Int16: " + sh + " " + check(Math.Sign(sh)));        Console.WriteLine("Int32: " + i + " " + check(Math.Sign(i)));        Console.WriteLine("Int64: " + l + " " + check(Math.Sign(l)));        Console.WriteLine("SByte: " + sb + " " + check(Math.Sign(sb)));        Console.WriteLine("Single: " + f + " " + check(Math.Sign(f)));      }      // function to check whether the input     // number is greater than zero or not    public static String check(int compare)    {        if (compare == 0)            return "equal to zero";                      else if (compare < 0)            return "less than zero";                      else            return "greater than zero";    }}
Decimal: 150 greater than zero
Double: 34.5432 greater than zero
Int16: 0 equal to zero
Int32: -5678 less than zero
Int64: 598964564 greater than zero
SByte: -34 less than zero
Single: 56.89 greater than zero

CSharp-Math
CSharp-method
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
C# Dictionary with examples
C# | Delegates
C# | Method Overriding
C# | Abstract Classes
Difference between Ref and Out keywords in C#
C# | Replace() Method
Extension Method in C#
C# | Class and Object
C# | Constructors
Introduction to .NET Framework