Single - Sign
Returns a value indicating the sign of a single-precision floating-point numbers.
public static void Main() { string str = "{0,20} is {1} zero."; float[] values = { Single.MaxValue, 16.354e-12F, 15.098123F, 0F, -19.069713F, -15.058e17F, Single.MinValue }; foreach (float value in values) { // C# Extension Method: Single - Sign Console.WriteLine(str, value, Display(value.Sign())); } } public static String Display(int compare) { if (compare == 0) return "equal to"; else if (compare < 0) return "less than"; else return "greater than"; }
View Source
using System; public static partial class Extensions { /// <summary> /// Returns a value indicating the sign of a single-precision floating-point number. /// </summary> /// <param name="value">A signed number.</param> /// <returns> /// A number that indicates the sign of , as shown in the following table.Return value Meaning -1 is less than /// zero. 0 is equal to zero. 1 is greater than zero. /// </returns> public static Int32 Sign(this Single value) { return Math.Sign(value); } }