C# 中的 Double.IsNegativeInfinity() 方法


C# 中的 Double.IsNegativeInfinity() 方法用于返回一个值,该值指示指定数字是否等于负无穷大。

语法

语法如下 −

public static bool IsNegativeInfinity (double val);

其中,val 是一个双精度浮点数。

示例

现在让我们看一个示例 −

 在线示例

using System;
public class Demo {
   public static void Main(){
      double d = 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));
   }
}

输出

这将产生以下输出 −

Double Value = NaN
HashCode of Double Value = -524288
TypeCode of Double Value = Double
Positive Infinity? = False
Check whether the specified value is NaN? = True
Does the value evaluate to negative infinity? = False

示例

现在让我们再看一个示例 −

 在线示例

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));
   }
}

输出

这将产生以下输出 −

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

更新于: 03-12-2019

37 次浏览

开启你的职业 生涯

获得认证,完成课程

开始学习
广告