System.Math.Sign Method

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

Syntax

public static int Sign (double value)

Parameters

value
A signed number.

Returns

A number that indicates the sign of value, as shown in the following table.

-1

value is less than zero.

0

value is equal to zero.

1

value is greater than zero.

Exceptions

TypeReason
ArithmeticException value is equal to double.NaN.

Remarks

Documentation for this section has not yet been entered.

Example

The following example demonstrates using the Math.Sign(sbyte)(double) method.

C# Example

using System;

public class MathSignExample
{

   public static void Main()
   {

      Double d1 = Math.Sign(4.4);
      Double d2 = Math.Sign(0.0);
      Double d3 = Math.Sign(-4.5);
      Console.WriteLine("Math.Sign(4.4) returns {0}", d1);
      Console.WriteLine("Math.Sign(0.0) returns {0}", d2);
      Console.WriteLine("Math.Sign(-4.5) returns {0}", d3);

   }

}

The output is

Math.Sign(4.4) returns 1
Math.Sign(0.0) returns 0
Math.Sign(-4.5) returns -1

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0