C#中的 Double.IsPositiveInfinity() 方法
C# 中的 Double.IsPositiveInfinity() 方法用于返回一个布尔值,指示指定数字是否等于正无穷大。
语法
语法如下 -
public static bool IsPositiveInfinity (double val);
其中,val 是双精度浮点数。
示例
现在让我们看一个示例 -
using System; public class Demo { public static void Main() { double d = 1.0/0.0; Console.WriteLine("Double Value = "+d); Console.WriteLine("HashCode of Double Value = "+d.GetHashCode()); TypeCode type = d.GetTypeCode(); Console.WriteLine("TypeCode of Double Value = "+type); Console.WriteLine("Positive Infinity? = "+Double.IsInfinity(d)); Console.WriteLine("Check whether the specified value is NaN? = "+Double.IsNaN(d)); Console.WriteLine("Does the value evaluate to negative infinity? = "+Double.IsNegativeInfinity(d)); Console.WriteLine("Does the value evaluate to positive infinity? = "+Double.IsPositiveInfinity(d)); } }
输出
它会产生以下输出 -
Double Value = ∞ HashCode of Double Value = 2146435072 TypeCode of Double Value = Double Positive Infinity? = True Check whether the specified value is NaN? = False Does the value evaluate to negative infinity? = False Does the value evaluate to positive infinity? = True
示例
现在让我们看另一个示例 -
using System; public class Demo { public static void Main() { double d = -50.0/0.0; Console.WriteLine("Double Value = "+d); Console.WriteLine("HashCode of Double Value = "+d.GetHashCode()); TypeCode type = d.GetTypeCode(); Console.WriteLine("TypeCode of Double Value = "+type); Console.WriteLine("Positive Infinity? = "+Double.IsInfinity(d)); Console.WriteLine("Check whether the specified value is NaN? = "+Double.IsNaN(d)); Console.WriteLine("Does the value evaluate to negative infinity? = "+Double.IsNegativeInfinity(d)); Console.WriteLine("Does the value evaluate to positive infinity? = "+Double.IsPositiveInfinity(d)); } }
输出
它会产生以下输出 -
Double Value = -∞ HashCode of Double Value = -1048576 TypeCode of Double Value = Double Positive Infinity? = True Check whether the specified value is NaN? = False Does the value evaluate to negative infinity? = True Does the value evaluate to positive infinity? = False
广告