Single.IsNegative() วิธีการใน C# ส่งกลับค่าที่ระบุว่าตัวเลขที่ระบุประเมินเป็นค่าอนันต์ค่าลบหรือไม่
ไวยากรณ์
ไวยากรณ์มีดังนี้ −
public static bool IsNegativeInfinity (float val);
ด้านบน val พารามิเตอร์คือตัวเลขทศนิยมที่มีความแม่นยำเพียงจุดเดียว
ตัวอย่าง
เรามาดูตัวอย่างกัน −
using System; public class Demo { public static void Main() { float f1 = 5.0f/0.0f; float f2 = 0.0f/0.0f; Console.WriteLine("Value1 = "+f1); Console.WriteLine("Hashcode for Value1 = "+f1.GetHashCode()); Console.WriteLine("TypeCode for Value1 = "+f1.GetTypeCode()); Console.WriteLine("Is Value1 value is positive or negative infinity? = "+Single.IsInfinity(f1)); Console.WriteLine("Is Value1 NaN? = "+Single.IsNaN(f1)); Console.WriteLine("Is Value1 a negative infinity? = "+Single.IsNegativeInfinity(f1)); Console.WriteLine("\nValue2 = "+f2); Console.WriteLine("Hashcode for Value2 = "+f2.GetHashCode()); Console.WriteLine("TypeCode for Value2 = "+f2.GetTypeCode()); Console.WriteLine("Is Value2 value is positive or negative infinity? = "+Single.IsInfinity(f2)); Console.WriteLine("Is Value2 NaN? = "+Single.IsNaN(f2)); Console.WriteLine("Is Value2 a negative infinity? = "+Single.IsNegativeInfinity(f2)); } }
ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
Value1 = ∞ Hashcode for Value1 = 2139095040 TypeCode for Value1 = Single Is Value1 value is positive or negative infinity? = True Is Value1 NaN? = False Is Value1 a negative infinity? = False Value2 = NaN Hashcode for Value2 = -4194304 TypeCode for Value2 = Single Is Value2 value is positive or negative infinity? = False Is Value2 NaN? = True Is Value2 a negative infinity? = False
ตัวอย่าง
เรามาดูตัวอย่างอื่นกัน −
using System; public class Demo { public static void Main() { float f1 = -25.0f/0.0f; float f2 = Single.MinValue; Console.WriteLine("Value1 = "+f1); Console.WriteLine("Hashcode for Value1 = "+f1.GetHashCode()); Console.WriteLine("TypeCode for Value1 = "+f1.GetTypeCode()); Console.WriteLine("Is Value1 value is positive or negative infinity? = "+Single.IsInfinity(f1)); Console.WriteLine("Is Value1 NaN? = "+Single.IsNaN(f1)); Console.WriteLine("Is Value1 a negative infinity? = "+Single.IsNegativeInfinity(f1)); Console.WriteLine("\nValue2 = "+f2); Console.WriteLine("Hashcode for Value2 = "+f2.GetHashCode()); Console.WriteLine("TypeCode for Value2 = "+f2.GetTypeCode()); Console.WriteLine("Is Value2 value is positive or negative infinity? = "+Single.IsInfinity(f2)); Console.WriteLine("Is Value2 NaN? = "+Single.IsNaN(f2)); Console.WriteLine("Is Value2 a negative infinity? = "+Single.IsNegativeInfinity(f2)); } }
ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
Value1 = -∞ Hashcode for Value1 = -8388608 TypeCode for Value1 = Single Is Value1 value is positive or negative infinity? = True Is Value1 NaN? = False Is Value1 a negative infinity? = True Value2 = -3.402823E+38 Hashcode for Value2 = -8388609 TypeCode for Value2 = Single Is Value2 value is positive or negative infinity? = False Is Value2 NaN? = False Is Value2 a negative infinity? = False