C# Math Sign(Single)
Description
Math Sign(Single)
returns a value indicating the sign
of a single-precision floating-point number.
Syntax
Math.Sign(Single)
has the following syntax.
public static int Sign(
float value
)
Parameters
Math.Sign(Single)
has the following parameters.
value
- A signed number.
Returns
Math.Sign(Single)
method returns 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.
Example
The following example demonstrates how to use the Sign(Single) method to determine the sign of a Single value and display it to the console.
using System;// ww w.ja v a 2 s.co m
class Sample
{
public static void Main()
{
float xSingle1 = 0.0f;
Console.WriteLine(Test(Math.Sign(xSingle1)));
}
public static String Test(int compare)
{
if (compare == 0)
return "equal to";
else if (compare < 0)
return "less than";
else
return "greater than";
}
}
The code above generates the following result.