Export (0) Print
Expand All

Math.Sign Method (Double)

Returns a value indicating the sign of a double-precision floating-point number.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static int Sign(
	double value
)

Parameters

value
Type: System.Double

A signed number.

Return Value

Type: System.Int32
A number that indicates the sign of value, as shown in the following table.

Return value

Meaning

-1

value is less than zero.

0

value is equal to zero.

1

value is greater than zero.

ExceptionCondition
ArithmeticException

value is equal to NaN.

The following example demonstrates how to use the Sign(Double) method to determine the sign of a Double value and display it to the console.

// This example demonstrates Math.Sign() 
using System;

class Sample 
{
    public static void Main() 
    {
    string str = "{0}: {1,3} is {2} zero.";
    string nl = Environment.NewLine;

    byte     xByte1    = 0;	
    short    xShort1   = -2;
    int      xInt1     = -3;
    long     xLong1    = -4;
    float    xSingle1  = 0.0f;
    double   xDouble1  = 6.0;
    Decimal  xDecimal1 = -7m;

// The following type is not CLS-compliant. 
    sbyte    xSbyte1   = -101;

    Console.WriteLine("{0}Test the sign of the following types of values:", nl);
    Console.WriteLine(str, "Byte   ", xByte1, Test(Math.Sign(xByte1)));
    Console.WriteLine(str, "Int16  ", xShort1, Test(Math.Sign(xShort1)));
    Console.WriteLine(str, "Int32  ", xInt1, Test(Math.Sign(xInt1)));
    Console.WriteLine(str, "Int64  ", xLong1, Test(Math.Sign(xLong1)));
    Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)));
    Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)));
    Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)));
//
    Console.WriteLine("{0}The following type is not CLS-compliant.", nl);
    Console.WriteLine(str, "SByte  ", xSbyte1, Test(Math.Sign(xSbyte1)));
    }
// 
    public static String Test(int compare)
    {
    if (compare == 0) 
       return "equal to";
    else if (compare < 0)  
        return "less than";
    else  
        return "greater than";
    }
}
/*
This example produces the following results:

Test the sign of the following types of values:
Byte   :   0 is equal to zero.
Int16  :  -2 is less than zero.
Int32  :  -3 is less than zero.
Int64  :  -4 is less than zero.
Single :   0 is equal to zero.
Double :   6 is greater than zero.
Decimal:  -7 is less than zero.

The following type is not CLS-compliant.
SByte  : -101 is less than zero.
*/

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft